im new to Python (version 3.41) and I have a problem with printing the result of using map and filter function. How can I find these results?
>>> def double(n):
return n*2
>>> li = [1,2,3]
>>> map(double, li)
<map object at 0x000000000333DCF8>
>>> print(map(double,li))
<map object at 0x000000000333DC50>
Try either :
print(list(map(double,li))
Or :
for item in map(double,li):
print(item)
In Python 3.4 map will return an iterator instead of a list (as it did in 2.7+). This is great as far as memory footprint is concerned but it doesn't map well to printing (pun intended)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With