PyDocs

Functional Programming Modules

Functional Programming Modules

itertools

Functional tools for creating and using iterators.

Infinite iterators:
count(start=0, step=1) --> start, start+step, start+2*step, ...
cycle(p) --> p0, p1, ... plast, p0, p1, ...
repeat(elem [,n]) --> elem, elem, elem, ... endlessly or up to n times

Iterators terminating on the shortest input sequence:
accumulate(p[, func]) --> p0, p0+p1, p0+p1+p2
batched(p, n) --> [p0, p1, ..., p_n-1], [p_n, p_n+1, ..., p_2n-1], ...
chain(p, q, ...) --> p0, p1, ... plast, q0, q1, ...
chain.from_iterable([p, q, ...]) --> p0, p1, ... plast, q0, q1, ...
compress(data, selectors) --> (d[0] if s[0]), (d[1] if s[1]), ...
dropwhile(predicate, seq) --> seq[n], seq[n+1], starting when predicate fails
groupby(iterable[, keyfunc]) --> sub-iterators grouped by value of keyfunc(v)
filterfalse(predicate, seq) --> elements of seq where predicate(elem) is False
islice(seq, [start,] stop [, step]) --> elements from
       seq[start:stop:step]
pairwise(s) --> (s[0],s[1]), (s[1],s[2]), (s[2], s[3]), ...
starmap(fun, seq) --> fun(*seq[0]), fun(*seq[1]), ...
tee(it, n=2) --> (it1, it2 , ... itn) splits one iterator into n
takewhile(predicate, seq) --> seq[0], seq[1], until predicate fails
zip_longest(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ...

Combinatoric generators:
product(p, q, ... [repeat=1]) --> cartesian product
permutations(p[, r])
combinations(p, r)
combinations_with_replacement(p, r)
Symbols in itertools

a

accumulate
Return series of accumulated sums (or other binary function results).

b

batched
Batch data into tuples of length n.

c

chain
Return a chain object whose .__next__() method returns elements from the first iterable until it is exhausted, then elements from the next iterable, until all of the iterables are exhausted.
combinations
Return successive r-length combinations of elements in the iterable.
combinations_with_replacement
Return successive r-length combinations of elements in the iterable allowing individual elements to have successive repeats.
compress
Return data elements corresponding to true selector elements.
count
Return a count object whose .__next__() method returns consecutive values.
cycle
Return elements from the iterable until it is exhausted.

d

dropwhile
Drop items from the iterable while predicate(item) is true.

f

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

g

groupby
make an iterator that returns consecutive keys and groups from the iterable

i

islice
islice(iterable, stop) --> islice object islice(iterable, start, stop[, step]) --> islice object

p

pairwise
Return an iterator of overlapping pairs taken from the input iterator.
permutations
Return successive r-length permutations of elements in the iterable.
product
Cartesian product of input iterables.

r

repeat
for the specified number of times.

s

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

t

takewhile
Return successive entries from an iterable as long as the predicate evaluates to true for each entry.
tee
Returns a tuple of n independent iterators.

z

zip_longest
Return a zip_longest object whose .__next__() method returns a tuple where the i-th element comes from the i-th iterable argument.