I have a list with mixed sequences like
[1,2,3,4,5,2,3,4,1,2]
I want to know how I can use itertools to split a list into ascending sequences, shortening the list while decreasing the points. For example, the above will output
[[1, 2, 3, 4, 5], [2, 3, 4], [1, 2]]
this was obtained by noting that the sequence decreases by 2, so we cut the first bit there, and reduce the other with one cut there.
Another example is the sequence
[3,2,1]
the conclusion should be
[[3], [2], [1]]
If this sequence increases, we return the same sequence. for instance
[1,2,3]
returns the same result. iee
[[1, 2, 3]]
For a repeating list, e.g.
[ 1, 2,2,2, 1, 2, 3, 3, 1,1,1, 2, 3, 4, 1, 2, 3, 4, 5, 6]
the conclusion should be
[[1, 2, 2, 2], [1, 2, 3, 3], [1, 1, 1, 2, 3, 4], [1, 2, 3, 4, 5, 6]]
What I did for this is to define the following function
def splitter (L):
result = []
tmp = 0
initialPoint=0
for i in range(len(L)):
if (L[i] < tmp):
tmpp = L[initialPoint:i]
result.append(tmpp)
initialPoint=i
tmp = L[i]
result.append(L[initialPoint:])
return result
100%, itertools, . itertools, ?