If the container was its own iterator (for example, provided __next__
), you could iterate over it only in one place. You would not have independent iterators. Each call __next__
will give the next value in the container, and you cannot return to the first value; you have a generator that can only ever give values in a container only once.
By creating separate iterators for a given container, you can iterate independently:
>>> lst = ['foo', 'bar', 'baz']
>>> it1 = iter(lst)
>>> it2 = iter(lst)
>>> next(it1)
'foo'
>>> next(it2)
'foo'
>>> list(it1)
['bar', 'baz']
>>> next(it2)
'bar'