How to print map object with Python 3? [duplicate]

You have to turn the map into a list or tuple first. To do that,

print(list(F_temps))

This is because maps are lazily evaluated, meaning the values are only computed on-demand. Let’s see an example

def evaluate(x):
    print(x)

mymap = map(evaluate, [1,2,3]) # nothing gets printed yet
print(mymap) # <map object at 0x106ea0f10>

# calling next evaluates the next value in the map
next(mymap) # prints 1
next(mymap) # prints 2
next(mymap) # prints 3
next(mymap) # raises the StopIteration error

When you use map in a for loop, the loop automatically calls next for you, and treats the StopIteration error as the end of the loop. Calling list(mymap) forces all the map values to be evaluated.

result = list(mymap) # prints 1, 2, 3

However, since our evaluate function has no return value, result is simply [None, None, None]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)