In the following code, the counter loops with two lists of elements. I expected the counter to be called twice, but it is called three times. Why?
def equivalent_count(start=0, step=1):
"""From python docs for itertools.count."""
n = start
while True:
print('count in loop =', n)
yield n
n += step
c = equivalent_count()
l = [0, 1]
for i, j in zip(c, l):
pass
Output:
count in loop = 0
count in loop = 1
count in loop = 2
Documents for zipstate, "The iterator stops when the shortest input iterable is exhausted."
source
share