May-15-2020, 02:16 PM
list1 = [1,2,3,4,5,6,7,8,9,10] squared = map(lambda x:x**2, filter(lambda x:x%2==0, list1)) print(squared)The output i expect is
Output:4
However, it comes as Output:<map object at 0x1076aa150>
Why does this happen? I went through several sites, I tried running code. According to this site, the code is # Python program to demonstrate working # of map. # Return double of n def addition(n): return n + n # We double all numbers using map() numbers = (1, 2, 3, 4) result = map(addition, numbers) print(list(result))And the output indeed is as expected,
Output:[2, 4, 6, 8]
I'm confused, why am I getting this problem, and what is it's cause? Any help would be appreciated
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs