(For python 3)
In the python docs, you can see that the list()
function takes an iterable.
In the python docs, you can also see that the next()
funciton takes an iterator.
So I did this in IDLE:
>>> var = map(lambda x: x+5, [1,2,3])
>>> var
>>> next(v)
>>> list(v)
Which gives the output:
<map object at 0x000000000375F978>
6
[7,8]
Frankly, this isn't what I expected. Is a map object an iterator or an iterable? Is there even a difference? Clearly both the list()
and next()
functions work on the map object, whatever it is.
Why do they both work?