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.
-
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)) # []