itertools

Source code: itertools.seq

itertools.combinations(pool, r: int)

Return successive r-length combinations of elements in the iterable.

combinations(range(4), 3) –> (0,1,2), (0,1,3), (0,2,3), (1,2,3)

itertools.combinations_with_replacement(pool, r: int)

Return successive r-length combinations of elements in the iterable allowing individual elements to have successive repeats.

class itertools.islice

Make an iterator that returns selected elements from the iterable.

Magic methods:

__new__[T](iterable: Generator[T], stop: Optional[int])
__new__[T](iterable: Generator[T], start: Optional[int], stop: Optional[int], step: Optional[int] = None)
itertools.count(start=0, step=1)

Return a count object whose __next__ method returns consecutive values.

itertools.repeat(object, times: Optional[int] = None)

Make an iterator that returns a given object over and over again.

itertools.cycle(iterable)

Cycles repeatedly through an iterable.

itertools.compress(data, selectors)

Return data elements corresponding to true selector elements. Forms a shorter iterator from selected data elements using the selectors to choose the data elements.

itertools.dropwhile(predicate, iterable)

Drop items from the iterable while predicate(item) is true. Afterwards, return every element until the iterable is exhausted.

itertools.takewhile(predicate, iterable)

Return successive entries from an iterable as long as the predicate evaluates to true for each entry.

itertools.filterfalse(predicate, iterable)

Return those items of iterable for which function(item) is false.

itertools.permutations(pool, r: Optional[int] = None)

Return successive r-length permutations of elements in the iterable.

class itertools.accumulate

Make an iterator that returns accumulated sums, or accumulated results of other binary functions (specified via the optional func argument).

Magic methods:

__new__(iterable, func=lambda a, b: ..., initial=0)
__new__(iterable, func=lambda a, b: ...)
class itertools.chain

Make an iterator that returns elements from the first iterable until it is exhausted, then proceeds to the next iterable, until all of the iterables are exhausted.

Magic methods:

__new__(*iterables)

Methods:

from_iterable(iterables)
itertools.starmap(function, iterable)

Return an iterator whose values are returned from the function evaluated with an argument tuple taken from the given sequence.

itertools.groupby[S, T](iterable: Generator[T], key: Callable[T, S] = NoneType)

Make an iterator that returns consecutive keys and groups from the iterable.

class itertools.zip_longest

Make an iterator that aggregates elements from each of the iterables. If the iterables are of uneven length, missing values are filled-in with fillvalue. Iteration continues until the longest iterable is exhausted.

Magic methods:

__new__(*args, fillvalue)
__new__(*args)
class itertools.product

Cartesian product of input iterables.

Magic methods:

__new__(*args)
__new__(*args, repeat: int)
itertools.tee[T](iterable: Generator[T], n: int = 2)

Return n independent iterators from a single iterable.