map () changed between python 2 and 3. In python 2, the map would apply the function to iterable and return a list. In python 3, map returns a generator that applies this function to the iterator when you loop it.
python2:
>>> print map(lambda x: x**2, range(10)) [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
python3:
>>> print(map(lambda x: x**2, range(10))) <map object at 0x7fb4b7c82250> >>> print([x for x in map(lambda x: x**2, range(10))]) [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
source share