In [1]:
x = [1, 2, 3] #the Iterable
y = iter(x) #the Iterator
z = iter(x) #the Iterator

print(next(y))
print(next(z))
print(type(x))
print(type(y))
1
1
<class 'list'>
<class 'list_iterator'>

Infinite Sequence

In [2]:
from itertools import count
counter = count(start=13)
next(counter)
Out[2]:
13

Infinite Sequences from Finite Sequences

In [3]:
from itertools import cycle
colors = cycle(['red', 'white', 'blue'])
print(next(colors))
print(next(colors))
print(next(colors))
print(next(colors))
red
white
blue
red

Finite Sequences from Infinite Sequences

In [4]:
from itertools import islice
colors = cycle(['red', 'white', 'blue'])
limited = islice(colors, 0, 4)
for x in limited:
    print(x)
red
white
blue
red