might be a dumb question but why when I try to use map() function on an already existing list:
nums = [1,2,3,4,5]
result = map(lambda num: num+num , nums)
print(result)
it returns me: <map object at 0x7f41cef17130> , instead of my result;
on the contrary when I do this:
nums = 1,2,3,4,5
result = list(map(lambda num: num+num , nums))
print(result)
it does print me my desired result: [2, 4, 6, 8, 10]
mapreturns amapobject always.mapobjects are iterators. You need to iterate over the object to get each individual value. One way is to create alistout of it, or atuple, or whatever you want.map()was called on an "existing list", just if you calledlist()on the result ofmap().