Previous topic

interval

Next topic

markup

This Page

itertools2

additions to itertools standard library

itertools2.take(n, iterable)[source]

Take first n elements from iterable

itertools2.index(n, iterable)[source]

Returns the nth item

itertools2.first(iterable)[source]

Take first element in the iterable

itertools2.last(iterable)[source]

Take last element in the iterable

itertools2.take_every(n, iterable)[source]

Take an element from iterator every n elements

itertools2.drop(n, iterable)[source]

Drop n elements from iterable and return the rest

itertools2.ilen(it)[source]

Return length exhausing an iterator

itertools2.irange(start_or_end, optional_end=None)[source]

Return iterable that counts from start to end (both included).

itertools2.arange(start, stop, step=1.0)[source]

range for floats or other types

itertools2.ilinear(start, end, n)[source]

return iterator over n values linearly interpolated between (and including) start and end

itertools2.flatten(lstlsts)[source]

Flatten a list of lists

itertools2.compact(it)[source]

Filter None values from iterator

itertools2.groups(iterable, n, step)[source]

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

itertools2.compose(f, g)[source]

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

itertools2.iterate(func, arg)[source]

After Haskell’s iterate: apply function repeatedly.

itertools2.tails(seq)[source]

Get tails of a sequence: tails([1,2,3]) -> [1,2,3], [2,3], [3], [].

itertools2.ireduce(func, iterable, init=None)[source]

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

itertools2.unique(iterable, key=None)[source]

List unique elements, preserving order. Remember all elements ever seen.

itertools2.identity(x)[source]

Do nothing and return the variable untouched

itertools2.occurrences(it, exchange=False)[source]

Return dictionary with occurrences from iterable

itertools2.product(*iterables, **kwargs)[source]

http://stackoverflow.com/questions/12093364/cartesian-product-of-large-iterators-itertools

itertools2.any(seq, pred=<type 'bool'>)[source]

Return True if pred(x) is True for at least one element in the iterable

itertools2.all(seq, pred=<type 'bool'>)[source]

Return True if pred(x) is True for all elements in the iterable

itertools2.no(seq, pred=<type 'bool'>)[source]

Returns True if pred(x) is False for every element in the iterable

itertools2.takenth(n, iterable)[source]

Returns the nth item

itertools2.takeevery(n, iterable)[source]

Take an element from iterator every n elements

itertools2.icross(*sequences)[source]

Cartesian product of sequences (recursive version)

itertools2.get_groups(iterable, n, step)[source]

Make groups of ‘n’ elements from the iterable advancing ‘step’ elements each iteration

itertools2.quantify(iterable, pred=<type 'bool'>)[source]

Count how many times the predicate is true

itertools2.pairwise(iterable)[source]

s -> (s0,s1), (s1,s2), (s2, s3), ...

itertools2.rand_seq(size)[source]

generates values in random order equivalent to using shuffle in random, without generating all values at once

itertools2.all_pairs(size)[source]

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

itertools2.split(iterable, condition)[source]

@return list of elements in iterable that satisfy condition, and those that don’t

itertools2.next_permutation(seq, pred=<built-in function cmp>)[source]

Like C++ std::next_permutation() but implemented as generator. Yields copies of seq. see http://blog.bjrn.se/2008/04/lexicographic-permutations-using.html

class itertools2.iter2(iterable)[source]

Bases: object

Takes in an object that is iterable. http://code.activestate.com/recipes/578092-flattening-an-arbitrarily-deep-list-or-any-iterato/ Allows for the following method calls (that should be built into iterators anyway...) calls: - append - appends another iterable onto the iterator. - insert - only accepts inserting at the 0 place, inserts an iterable before other iterables. - adding. an iter2 object can be added to another object that is iterable. i.e. iter2 + iter (not iter + iter2). It’s best to make all objects iter2 objects to avoid syntax errors. :D

__init__(iterable)[source]
append(iterable)[source]
insert(place, iterable)[source]
__add__(iterable)[source]
next()[source]
__iter__()[source]
__weakref__

list of weak references to the object (if defined)

itertools2.iflatten(iterable)[source]

flatten a list of any depth