For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
itertools
Provides iterator utilities for common iteration patterns.
This module includes functions for creating specialized iterators:
count()- Creates an infinite counter with customizable start and step valuescycle()- Cycles through an iterable indefinitelydrop_while()- Drops elements while predicate is true, then yields the restproduct()- Computes the Cartesian product of two, three, or four iterablesrepeat()- Repeats an element a specified number of timestake_while()- Yields elements while predicate is true
These utilities enable functional-style iteration patterns and composable iterator operations.
Functions
-
count: Constructs an iterator that starts at the valuestartwith a stride ofstep. -
cycle: Creates an iterator that cycles through an iterable indefinitely. -
drop_while: Creates an iterator that drops elements while predicate returns True. -
product: Returns an iterator that yields tuples of the elements of the outer product of the iterables. -
repeat: Constructs an iterator that repeats the given element a specified number of times. -
take_while: Creates an iterator that yields elements while predicate returns True.