Skip to main content

Mojo module

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.

Was this page helpful?