![]() |
VOOZH | about |
Iterator is defined as object types which contains values that can be accessed or iterated using a loop. There are different iterators that come built-in with Python such as lists, sets, etc. Itertools is the Python module that contains some inbuilt functions for generating sequences using iterators. This module provides various functions that work on iterators to produce complex iterators. This module works as a fast, memory-efficient tool that is used either by themselves or in combination to form iterator algebra. There are different types of Iterators
The below-mentioned Python program illustrates the functioning of the cycle function. It takes string type as an argument and produces the infinite sequence.
Output:
Sequence 1 G e e k s Sequence 2 G e e k s Sequence 3 G e e k s
The itertools.cycle function also works with the Python Lists. The below-mentioned Python program illustrates the functioning. It takes the Python list as an argument and produces the infinite sequence.
Output:
Sequence 1 1 2 3 Sequence 2 1 2 3 Sequence 3 1 2 3