Iterable versus iterator
Learn in depth →An iterable supplies an iterator. An iterator retains a position and produces values through next.
iterator = iter(iterable)
next(iterator, default)Example
source = [10, 20]
a, b = iter(source), iter(source)
print(next(a), next(a), next(b))
print(next(a, "end"))Result
10 20 10 end
Watch for: A consumed iterator is not automatically reset. Creating an iterator from a list can start an independent traversal.
Practise this topic →