Skip to content

bagofstuff.itertools

Tools for iterating or working on iterable things.

Direction

Direction = Literal['forward', 'backward']

Directions used with starting_at.

starting_at

starting_at(
    items: Iterable[T],
    start_at: int = 0,
    direction: Direction = "forward",
) -> Iterator[T]

Create an iterator of all items starting at a given point.

This function creates an iterator of all the items in the initial iterable, starting at the given point and wrapping around the end if necessary.

Parameters:

Name Type Description Default

items

Iterable[T]

The items to iterate over.

required

start_at

int

The item to start out at.

0

direction

Direction

The direction to iterate in.

'forward'

Returns:

Type Description
Iterator[T]

An iterable of all the items starting at the given point.