0

I have

List1 = [[...11,12,13,14,7,8,9],[0,1,2,3]]   

where ... are consecutive integers starting from from 0 up to 11

I want

List2 = [[11,12,13,14],[7,8,9],[0,1,2,3]]

EDIT:

Found the answer:

from Python: split list of integers based on step between them

[list(g) for k, g in groupby(listName, key=lambda i,j=count(): i-next(j))]

Turns out, that wasn't what I was looking for. I need to be able to split the list of lists of integers by consecutive order ONLY if the next integer in that list was of lesser value than the preceding integer. e.g.

[[0,1,2,15,16,17,2,3,4,6,8,9]]

should be split into [[0,1,2,15,16,17],[2,3,4,6,8,9]]

Community
  • 1
  • 1
Mike Issa
  • 295
  • 2
  • 13
  • 4
    You have a test case, now write some code. If you get really stuck, post what you have done and ask a specific question. But the answer is pretty simple. – Terry Jan Reedy Dec 14 '15 at 22:51
  • 2
    Your problem in underspecified. The title says 'list of integers', but the example is 'list of lists of integers'. Why does 0 disappear in the second list? If that is a typo, and the output should be the 'same' as the input, `[0,1,2,3]`, should the output object be the input object or a copy thereof? – Terry Jan Reedy Dec 14 '15 at 22:57
  • @TerryJanReedy thanks for helping me fix it up. I updated the post. – Mike Issa Dec 15 '15 at 15:12
  • topic moved to http://stackoverflow.com/questions/34294306/if-statement-in-list-comprehension-with-lambda – Mike Issa Dec 15 '15 at 16:27

0 Answers0