Iteration Classes

itertools.cycle()

Repeat elements indefinitely after saving the first traversal; an empty input ends immediately. Retaining input elements can consume memory.

Formal Syntax & Structure

python syntaxpython
itertools.cycle(iterable, /)

Parameters & Attributes

NameTypeDescription
iterableiterableInput values, consumed as needed.

Return Value

iterator

The iterator result described above.

Working Example

Example Snippetpython
import itertoolsprint(list(itertools.islice(itertools.cycle("AB"),5)))
Python Reference