It seems that converting iter. to list move the iter index to last element, why ?
l = iter([1, 2, 3])
x = list(l)
Traceback (most recent call last):
Because firstly, you are creating a new object. Secondly an iterator object doesn't have all it's item in memory it generates the item on demand, and once you got to the end there is no way back. That's why they call it one shot iterable. Therefor when you call the
list on an iterator you are creating new list object by consuming the iterator and preserving its items in a list.
For a better demonstration it does something like following:
In : l = iter([1, 2, 3]) In : x = [item for item in l] In : x Out: [1, 2, 3]