Rectangle 27 0

using map in python 3?


>>> x = map(lambda x: x + 1, [1, 2, 3])
>>> x
<map object at 0x7f8571319b90>
>>> list(x)
[2, 3, 4]

If you need a list, you can simply pass that iterator to list(). For example:

In Python 3, the map() builtin returns an iterator rather than a list, behaving somewhat like the Python 2 itertools.imap() function.

Note
Rectangle 27 0

using map in python 3?


import itertools

def product(a,b):
    return list(map(list, itertools.product(a, repeat=b))

print(sorted(product({0,1}, 3)))

Apply function to every item of iterable and return a list of the results.

In two words in Python 3 map

Return an iterator that applies function to every item of iterable, yielding the results.

Simply wrap it by a list this way:

Thanks that change made it work

While in python 2.7 it

Note