Is their anything wrong I have done or I did call it in a wrong way?
In:
map(lambda x: x * 3, [1, 2, 3])
Out:
<map object at 0x000001D06DF202E8>
Is their anything wrong I have done or I did call it in a wrong way?
In:
map(lambda x: x * 3, [1, 2, 3])
Out:
<map object at 0x000001D06DF202E8>
In python3 map is a generator, so it returns a generator object instead of a list. You can easily convert it into a list though:
list(map(lambda x: x * 3, [1, 2, 3]))
However as Julien said list comprehension is preferable if you are just trying to make a list:
[x*3 for x in [1,2,3]]
The main use of map is its lazy evaluation. This means that the entire set of results isn't all loaded into memory at once.
For instance:
a = map(str, range(100000))
for i in a:
...
In this situation a map would be preferable because you are not loading 100,000 strings into memory like a list comp would do.