I have
listName = [[0,1,2,15,16,17,2,3,4,6,8,9]]
My line of code
[list(g) for k, g in groupby(listName, key=lambda i,j=count(): i-next(j))]
is splitting listName
into [[0,1,2],[15,16,17],[2,3,4],[6,8,9]]
I want the split to happen only if the next number is less than the preceding number. i.e
I want my listName
to split into
[[0,1,2,15,16,17],[2,3,4,6,8,9]]
Thanks! :)
It is much easier to use a generator function, using
itertools.chain
to create an iterator and flatten your list: