Module itertools
[hide private]
[frames] | no frames]

Module 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:
izip(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... 
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
chain(p, q, ...) --> p0, p1, ... plast, q0, q1, ... 
takewhile(pred, seq) --> seq[0], seq[1], until pred fails
dropwhile(pred, seq) --> seq[n], seq[n+1], starting when pred fails
groupby(iterable[, keyfunc]) --> sub-iterators grouped by value of keyfunc(v)

Classes [hide private]
chain
chain(*iterables) --> chain object
count
count([firstval]) --> count object
cycle
cycle(iterable) --> cycle object
dropwhile
dropwhile(predicate, iterable) --> dropwhile object
groupby
groupby(iterable[, keyfunc]) -> create an iterator which returns (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
repeat
repeat(element [,times]) -> create an iterator which returns the element for the specified number of times.
starmap
starmap(function, sequence) --> starmap object
takewhile
takewhile(predicate, iterable) --> takewhile object
Functions [hide private]
 
tee(...)
tee(iterable, n=2) --> tuple of n independent iterators.