Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.

from counter import Counter

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

for c in cnt:
   print(c)

Output:

1
2
3