Using iterator


The class returned an iterator, we could use a for loop to iterate over the element. We tried to run through the iterator again, but it did not print anything. It was exhausted.

examples/iterators/simple_iterator.py
from counter import Counter

cnt = Counter()
for c in cnt:
   print(c)

for c in cnt:
   print(c)

1
2
3