Recently I was trying out something for ways to print a map()
result, where I came across *
I tried out this:
>>> def inc(x):
... return x+1
...
>>> a = map(inc,[1,2,3,4,5])
>>> print(*a)
2 3 4 5 6
>>> print(*a)
Here with a function inc()
I stored the map object result in a
. On printing it using print(*a)
,
I get the desired output. Running the command second time prints out nothing. Why?
I wondered that has anything happened to a
, and tried this to check type()
of a
:
>>> type(a)
<class 'map'>
But it seems to be all good. So why am I not able to print results using print(*a)
command a second time?
Even when I tried to print using [i for i in a]
, Its possible for the first time and not possible for the second, it gets me []
. What is the problem?