itertools

Functional tools for creating and using iterators.

Infinite iterators: count([n]) –> n, n+1, n+2, ... 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: chain(p, q, ...) –> p0, p1, ... plast, q0, q1, ... compress(data, selectors) –> (d[0] if s[0]), (d[1] if s[1]), ... dropwhile(pred, seq) –> seq[n], seq[n+1], starting when pred fails groupby(iterable[, keyfunc]) –> sub-iterators grouped by value of keyfunc(v) ifilter(pred, seq) –> elements of seq where pred(elem) is True ifilterfalse(pred, seq) –> elements of seq where pred(elem) is False islice(seq, [start,] stop [, step]) –> elements from

seq[start:stop:step]

imap(fun, p, q, ...) –> fun(p0, q0), fun(p1, q1), ... starmap(fun, seq) –> fun(*seq[0]), fun(*seq[1]), ... tee(it, n=2) –> (it1, it2 , ... itn) splits one iterator into n takewhile(pred, seq) –> seq[0], seq[1], until pred fails izip(p, q, ...) –> (p[0], q[0]), (p[1], q[1]), ... izip_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)

Functions

tee tee(iterable, n=2) –> tuple of n independent iterators.

Classes

chain chain(*iterables) –> chain object
combinations combinations(iterable, r) –> combinations object
combinations_with_replacement combinations_with_replacement(iterable, r) –> combinations_with_replacement object
compress compress(data, selectors) –> iterator over selected data
count count(start=0, step=1) –> count object
cycle cycle(iterable) –> cycle object
dropwhile dropwhile(predicate, iterable) –> dropwhile object
groupby (key, sub-iterator) grouped by each value of key(value).
ifilter ifilter(function or None, sequence) –> ifilter object
ifilterfalse ifilterfalse(function or None, sequence) –> ifilterfalse object
imap imap(func, *iterables) –> imap object
islice islice(iterable, [start,] stop [, step]) –> islice object
izip izip(iter1 [,iter2 [...]]) –> izip object
izip_longest izip_longest(iter1 [,iter2 [...]], [fillvalue=None]) –> izip_longest object
permutations permutations(iterable[, r]) –> permutations object
product product(*iterables) –> product object
repeat for the specified number of times. If not specified, returns the object
starmap starmap(function, sequence) –> starmap object
takewhile takewhile(predicate, iterable) –> takewhile object