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
| Name | Type | Description |
|---|---|---|
| iterable | iterable | Input 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)))