As the documentation of map()
explains, it returns an iterator (as opposed to the behavior on Python 2 which called the function in place).
This means that the function will not be called until the returned map object is iterated.
A possible solution would be to "force" the iteration by converting it to a list:
list(map(lambda x, y: self.tab.setItem(x, y, QTableWidgetItem()), x, y))
Which is roughly the same as:
[self.tab.setItem(x, y, QTableWidgetItem()) for x, y in zip(x, y)]
That said, consider that such usage of mapping or comprehensions is usually frown upon, as they do not really provide any benefit:
- there's no performance increase (on the contrary, you're creating a map object and then a list from it);[1]
- it makes debugging more difficult;
- it makes the code much less readable (and that's very important);
There are very few situations for which using an approach like this is actually required, and a for loop is almost always a better choice.
[1] list comprehensions offer performance benefits as they actually build the list object after all elements have been gathered, while using list.append()
continuously grows the existing list object (see this answer), but since you're not creating a list that will be actually used, those benefits are completely nullified, and a for loop is a clearer, better and faster choice.