^^Python. Iterators.    for x in X:

 

for x in y:
for x in X:

 

the Python interpreter checks whether X has an iterator interface.

The iterator interface can be checked  with the built-in iter function:

iter(X)

Exist an iterator object that provides the functionality required by the for loop

it gives access to the next object for as long as it's valid, with the built-in function next:

I = iter([2, 4, 6, 8, 10])

print(next(I))    -> 2

print(next(I))    -> 4

print(next(I))    -> 6

 

zip

>>> L = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

>>> for le,ri in zip(range(1, 11), L) : print(le, ri)

 

Links

https://nbviewer.jupyter.org/github/jakevdp/WhirlwindTourOfPython/blob/master/10-Iterators.ipynb