IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0.0b1
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 values
  • cycle() - Cycles through an iterable indefinitely
  • drop_while() - Drops elements while predicate is true, then yields the rest
  • product() - Computes the Cartesian product of two, three, or four iterables
  • repeat() - Repeats an element a specified number of times
  • take_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 value start with a stride of step.
  • 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.