iterlib: More itertools

More itertools

Functions

avg(seq[, empty])

Return the average of seq, or empty if the seq.

butlast(seq)

iterate over seq[:-1]

butn(seq, n)

iterate over seq[:-n]

chunked(iterable, n)

Break iterable into lists of length n:

chunks(start[, stop, step])

Returns a generator of tuples (offset, chunksize)

classify(s, keyfunc)

Split s according to keyfunc

consume(iterator, n)

Advance the iterator n-steps ahead.

dotproduct(vec1, vec2)

Returns the dot product (the sum of the product between each pair) between vec1 and vec2

drop(seq, n)

return an iterator over seq with n elements consumed

duplicates(s)

Find duplicates in the iterable s

first(it[, default])

rtype:

Optional[TypeVar(T)]

flatdict(d)

Given a dictionary, return a flat list where keys and values are interleaved.

flatten(s[, exclude, levels])

Return an iterator to the flattened items of sequence s

flattened(s[, exclude, levels, out])

Like flatten, but returns a list instead of an iterator

flattenonly(l, types)

Flatten only if subsequences are of type 'type'

ilen(seq)

Consume an iterable not reading it into memory; return the number of items.

intercalate(seq, item)

Intercalate item between elements of seq

interleave(seqs[, pass_exceptions])

Interleave a sequence of sequences

isiterable(obj[, exclude])

Returns True if obj is iterable

iterchunks(seq, chunksize)

Returns an iterator over chunks of seq of at most chunksize size.

last(seq)

Returns the last element of seq or None if seq is empty

mesh(xs, ys)

iterator over the lexicographical pairs

mesh3(A, B, C)

the same as mesh, but over 3 iterators

ncycles(seq, n)

Returns the sequence elements n times

nth(seq, n)

Returns the nth item

pad(seq[, element])

Returns the elements in seq and then return element indefinitely.

pairwise(iterable)

Similar to window(seq, size=2, step=1)

parse_range(start[, stop, step])

Given arguments as passed to range, resolved them in (start, stop, step)

partialavg(seq)

Return the partial average in seq

partialmul(seq[, start])

return the accumulated multiplication

partialreduce(seq, func[, start])

Return an iterator of the partial values of the reduce operation.

partialsum(seq[, start])

for each elem in seq return the partial sum

random_combination(iterable, r)

Random selection from itertools.combinations(iterable, r)

random_permutation(iterable[, r])

Random selection from itertools.permutations(iterable, r)

repeatfunc(func[, times])

Repeat calls to func with specified arguments.

reversed_enumerate(s)

The same as enumerate but reverses the sequence

take(seq, n)

returns the first n elements of seq as a list

unique(seq)

Return only unique elements of a sequence (keeps order)

window(iterable[, size, step])

iterate over subseqs of iterable

window_fixed_size(seq, size, maxstep)

A sliding window over subseqs of seq

zipflat(*seqs)

like izip but flat.

Classes

Accum([init])

Simple accumulator