First page Back Continue Last page Overview Image

Unendliche Iteratoren: cycle

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

Die Elemente des Iterators p werden solange geliefert, bis dieser aufgebraucht ist. Dann wird die Folge unendlich oft wiederholt:

>>> 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,