goulib.itertools2

additions to itertools standard library

Functions

accumulate(iterable[, func, skip_first, modulo])

Return running totals.

all(seq[, pred])

all_pairs(size)

generates all i,j pairs for i,j from 0-size

any(seq[, pred])

arange(start[, stop, step])

range for floats or other types (numpy.arange without numpy)

best(iterable[, key, n, reverse])

generate items corresponding to the n best values of key sort order

brent(iterable[, limit])

Detect a cycle in iterable using Floyd "tortue hand hare" algorithm

combinations_with_replacement(iterable, r)

combinations_with_replacement('ABC', 2) --> AA AB AC BB BC CC same as combinations_with_replacement except it doesn't generate duplicates

compose(f, g)

Compose two functions -> compose(f, g)(x) -> f(g(x))

compress(iterable[, key, buffer])

generates (item,count) pairs by counting the number of consecutive items in iterable)

count_unique(iterable[, key])

Count unique elements

decompress(iterable)

detect_cycle(iterable[, limit])

dictsplit(dic, keys)

extract keys from dic :param dic: dict source :param keys: iterable of dict keys :result: dict,dict : the first contains entries present in source, the second the remaining entries

diff(iterable1, iterable2)

generate items in sorted iterable1 that are not in sorted iterable2

drop(n, iterable)

Drop n elements from iterable and return the rest

ensure_sorted(iterable[, key])

makes sure iterable is sorted according to key

enumerates(iterable)

generalizes enumerate to dicts :result: key,value pair for whatever iterable type

every(n, iterable[, start])

Take an element from iterator every n elements

filter2(iterable, condition)

like python.filter but returns 2 lists : - list of elements in iterable that satisfy condition - list of those that don't

find(iterable, f)

Return first item in iterable where f(item) == True.

first(iterable)

first_match(iter1, iter2[, limit])

flatten(iterable[, donotrecursein])

iterator to flatten (depth-first) structure

floyd(iterable[, limit])

Detect a cycle in iterable using Floyd "tortue hand hare" algorithm

groups(iterable, n[, step])

Make groups of 'n' elements from the iterable advancing 'step' elements on each iteration

icross(*sequences)

Cartesian product of sequences (recursive version)

identity(x)

Do nothing and return the variable untouched

ifind(iterable, f[, reverse])

iterates through items in iterable where f(item) == True.

ilen(it)

index(value, iterable)

index_max(values[, key])

index_min(values[, key])

interleave(l1, l2)

intersect(*iterables)

generates itersection of N iterables

irange(start_or_end[, optional_end])

ireduce(func, iterable[, init])

Like python.reduce but using iterators (a.k.a scanl)

iremove(iterable, f)

removes items from an iterable based on condition :param iterable: iterable .

iscallable(f)

isiterable(obj)

isplit(iterable, sep[, include_sep])

split iterable by separators or condition :param sep: value or function(item) returning True for items that separate :param include_sep: bool.

itemgetter(iterable, i)

iterate(func, arg)

After Haskell's iterate: apply function repeatedly.

ith(iterable, i)

last(iterable)

linspace(start, end[, n])

iterator over n values linearly interpolated between (and including) start and end numpy.linspace without numpy

ndim(iterable)

number of dimensions of a mutidimensional array, without numpy

next_permutation(seq[, pred])

Like C++ std::next_permutation() but implemented as generator.

no(seq[, pred])

nth(n, iterable[, default])

occurences(iterable)

count number of occurences of each item in a finite iterable

pairwise(iterable[, op, loop])

iterates through consecutive pairs

product(*iterables, **kwargs)

Cartesian product of (infinite) input iterables.

quantify(iterable[, pred])

rand_seq(size)

record(iterable[, it, max])

return the index and value of iterable which exceed previous max

record_index(iterable[, it, max])

record_value(iterable[, it, max])

recurse(f, x)

removef(iterable, f)

removes items from an iterable based on condition :param iterable: iterable .

reshape(data, dims)

select(it1, it2, op)

shape(iterable)

shape of a mutidimensional array, without numpy

shuffle(ary)

sort_indexes(iterable[, key, reverse])

sorted_iterable(iterable[, key, buffer])

sorts an "almost sorted" (infinite) iterable

split(iterable, sep[, include_sep])

like https://docs.python.org/2/library/stdtypes.html#str.split, but for iterable :param sep: value or function(item) returning True for items that separate :param include_sep: bool.

subdict(d, keys)

extract "sub-dictionary" :param d: dict :param keys: container of keys to extract: :result: dict: :see: http://stackoverflow.com/questions/5352546/best-way-to-extract-subset-of-key-value-pairs-from-python-dictionary-object/5352649#5352649

swap(iterable)

tails(seq)

Get tails of a sequence

take(n, iterable)

takeevery(n, iterable[, start])

Take an element from iterator every n elements

takenth(n, iterable[, default])

tee(iterable[, n, copy])

tee or copy depending on type and goal

unique(iterable[, key, buffer])

generate unique elements, preserving order.

Classes

iter2(iterable)

Takes in an object that is iterable.

keep(iterable)

iterator that keeps the last value

Exceptions

SortingError