10.1.1.5. IterTools

class Patro.Common.IterTools.PairWiseManipulator[source]

Bases: object

This class is a template to manipulate an iterable with a pair wise iterator concept.

The method do() must be implemented in super-class.

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

_index_max()[source]

Return the index max of the list.

apply(iterable)[source]

Iterate over the iterable and call the method do() at each iteration until the last position is reached. The index position is incremented if the method return True.

del_item()[source]

Delete the item at the current index position.

del_next_item()[source]

Delete the item at the next index position.

do()[source]

Method called by method apply() to manipulate the list. Must return a boolean.

end()[source]

Test if the index position is at the end of the list.

next()[source]

Increment the index position.

pair()[source]

Return the pair from the current index position.

Patro.Common.IterTools.accumulate(iterable)[source]

Accumulate the values of an iterable to a new array.

Patro.Common.IterTools.closed_pairwise(iterable)[source]

Return a generator which generate a closed pair wise list from an iterable. s -> (s[0],s[1]), (s[1],s[2]), … (s[N], s[0])

Patro.Common.IterTools.multiwise(iterable, n=2)[source]

Return a generator which generate a multi wise list from an iterable. s -> (s[0],s[1],s[2],…), (s[1],s[2],s[3],…), … (…,s[N-2],s[N-1],s[N])

Examples:

a = (1,2,3,4,5)

list(multiwise(a, n=1))
# [(1,), (2,), (3,), (4,), (5,)]

list(multiwise(a, n=2))
# [(1, 2), (2, 3), (3, 4), (4, 5)]

list(multiwise(a, n=3))
# [(1, 2, 3), (2, 3, 4), (3, 4, 5)]

# list(multiwise(a, n=4))
# [(1, 2, 3, 4), (2, 3, 4, 5)]

list(multiwise(a, n=5))
# [(1, 2, 3, 4, 5)]

list(multiwise(a, n=6))
# []

list(multiwise(a, n=0))
# []
Patro.Common.IterTools.multiwise_interval(iterable_size, n=2)[source]
Patro.Common.IterTools.pairwise(iterable)[source]

Return a generator which generate a pair wise list from an iterable. s -> (s[0],s[1]), (s[1],s[2]), … (s[N-1],s[N])