itertools¶
Functions creating iterators for efficient looping.
Functions¶
itertools.count(start: int = 0, step: int = 1) -> Iterator[int]¶
Make an iterator that returns evenly spaced values starting with number start.
itertools.repeat(elem: T, n: int = -1) -> Iterator[T]¶
Make an iterator that returns object over and over again, optionally limited by n times.
itertools.cycle(iterable: list[T]) -> Iterator[T]¶
Make an iterator returning elements from the iterable and saving a copy of each.
itertools.compress(data: list[T], selectors: list[bool]) -> Iterator[T]¶
Make an iterator that filters elements from data returning only those that have a corresponding element in selectors that evaluates to True.
itertools.dropwhile(predicate: (T) -> bool, iterable: list[T]) -> Iterator[T]¶
Make an iterator that drops elements from the iterable as long as the predicate is True; afterwards, returns every element.
itertools.takewhile(predicate: (T) -> bool, iterable: list[T]) -> Iterator[T]¶
Make an iterator that returns elements from the iterable as long as the predicate is True.
itertools.filterfalse(predicate: (T) -> bool, iterable: list[T]) -> Iterator[T]¶
Make an iterator that filters elements from iterable returning only those for which the predicate is False.
itertools.islice(iterable: list[T], stop: int) -> Iterator[T]¶
Make an iterator that returns selected elements from the iterable.
itertools.islice_range(iterable: list[T], start: int, stop: int, step: int = 1) -> Iterator[T]¶
Make an iterator that returns selected elements from the iterable with start, stop, and step.
itertools.pairwise(iterable: list[T]) -> Iterator[tuple[T, T]]¶
Return successive overlapping pairs taken from the input iterable.
itertools.accumulate(iterable: list[int]) -> Iterator[int]¶
Make an iterator that returns accumulated sums.
itertools.accumulate(iterable: list[T], func: (T, T) -> T) -> Iterator[T]¶
Make an iterator that returns accumulated results of a binary function.
itertools.accumulate(iterable: list[T], func: (T, T) -> T, initial: T) -> Iterator[T]¶
Make an iterator that returns accumulated results of a binary function, starting with an initial value.
itertools.chain(first: list[T], second: list[T]) -> Iterator[T]¶
Make an iterator that returns elements from the first iterable until it is exhausted, then proceeds to the next iterable.
itertools.chain(first: list[T], second: list[T], third: list[T]) -> Iterator[T]¶
Make an iterator that returns elements from each iterable in turn until all are exhausted.
itertools.chain_from_iterable(iterables: list[list[T]]) -> Iterator[T]¶
Make an iterator that chains all iterables from a single list of iterables.
itertools.starmap(func: (T1, T2) -> R, iterable: list[tuple[T1, T2]]) -> Iterator[R]¶
Make an iterator that computes the function using arguments obtained from the iterable.
itertools.zip_longest(first: list[T], second: list[T], fillvalue: T) -> Iterator[tuple[T, T]]¶
Make an iterator that aggregates elements from each iterable, filling missing values with fillvalue.
itertools.groupby(iterable: list[T], key: (T) -> K) -> IEnumerable[tuple[K, list[T]]]¶
Make an iterator that returns consecutive keys and groups from the iterable.
itertools.product(first: list[T1], second: list[T2]) -> Iterator[tuple[T1, T2]]¶
Cartesian product of two input iterables, equivalent to nested for-loops.
itertools.product(first: list[T1], second: list[T2], third: list[T3]) -> Iterator[tuple[T1, T2, T3]]¶
Cartesian product of three input iterables, equivalent to nested for-loops.
itertools.combinations(iterable: list[T], r: int) -> Iterator[list[T]]¶
Return successive r-length combinations of elements in the iterable.
itertools.permutations(iterable: list[T], r: int = -1) -> Iterator[list[T]]¶
Return successive r-length permutations of elements in the iterable. A negative r means full length.
itertools.combinations_with_replacement(iterable: list[T], r: int) -> Iterator[list[T]]¶
Return successive r-length combinations of elements in the iterable allowing individual elements to be repeated.
itertools.repeat(elem: T, n: uint32) -> IEnumerable[T]¶
Make an iterator that returns object over and over again, limited by n times.
itertools.cycle(iterable: IEnumerable[T]) -> IEnumerable[T]¶
Make an iterator returning elements from the iterable and saving a copy of each.
itertools.compress(data: IEnumerable[T], selectors: IEnumerable[bool]) -> IEnumerable[T]¶
Make an iterator that filters elements from data returning only those with a corresponding True selector.
itertools.dropwhile(predicate: (T) -> bool, iterable: IEnumerable[T]) -> IEnumerable[T]¶
Make an iterator that drops elements as long as the predicate is True; afterwards, returns every element.
itertools.takewhile(predicate: (T) -> bool, iterable: IEnumerable[T]) -> IEnumerable[T]¶
Make an iterator that returns elements as long as the predicate is True.
itertools.filterfalse(predicate: (T) -> bool, iterable: IEnumerable[T]) -> IEnumerable[T]¶
Make an iterator that filters elements returning only those for which the predicate is False.
itertools.pairwise(iterable: IEnumerable[T]) -> IEnumerable[tuple[T, T]]¶
Return successive overlapping pairs taken from the input iterable.
itertools.islice(iterable: IEnumerable[T], stop: int) -> IEnumerable[T]¶
Make an iterator that returns selected elements from the iterable.
itertools.islice(iterable: IEnumerable[T], start: int, stop: int, step: int = 1) -> IEnumerable[T]¶
Make an iterator that returns selected elements from the iterable with start, stop, and step.
itertools.accumulate(iterable: IEnumerable[T], func: (T, T) -> T) -> IEnumerable[T]¶
Make an iterator that returns accumulated sums (or accumulated results of a binary function).
itertools.accumulate(iterable: IEnumerable[T], func: (T, T) -> T, initial: T) -> IEnumerable[T]¶
Make an iterator that returns accumulated results with an initial value.
itertools.chain(*iterables: IEnumerable[T]) -> IEnumerable[T]¶
Make an iterator that returns elements from the first iterable until it is exhausted, then proceeds to the next iterable.
Parameters:
iterables(*IEnumerable[T]) -- One or more iterables to chain together.
Returns: An iterator over the concatenated elements.
itertools.combinations(iterable: IEnumerable[T], r: int) -> IEnumerable[list[T]]¶
Return r-length combinations of elements in the iterable.
itertools.permutations(iterable: IEnumerable[T], r: int = -1) -> IEnumerable[list[T]]¶
Return successive r-length permutations of elements in the iterable.
itertools.combinations_with_replacement(iterable: IEnumerable[T], r: int) -> IEnumerable[list[T]]¶
Return r-length combinations of elements allowing individual elements to be repeated.
itertools.starmap(func: (T1, T2) -> R, iterable: IEnumerable[tuple[T1, T2]]) -> IEnumerable[R]¶
Make an iterator that computes the function using arguments obtained from the iterable.