First page Back Continue Last page Overview Graphics

Infinite Iterators: cycle

cycle(p) --> p0, p1, ... plast, p0, p1, …

Return elements from the iterable p until it is exhausted. Then repeat the sequence indefinitely.

>>> from itertools import cycle

>>> x = cycle("abcd")

>>> for _ in range(10):

... print(next(x), end=", ")

...

a, b, c, d, a, b, c, d, a, b,