我有
List1 = [[...11,12,13,14,7,8,9],[0,1,2,3]]
其中...
是从0到11
我想要
List2 = [[11,12,13,14],[7,8,9],[0,1,2,3]]
编辑:
找到答案:
来自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))]
事实证明,这不是我想要的。如果该列表中的下一个整数值小于前一个整数,我需要能够按连续顺序拆分整数列表列表。 e.g。
[[0,1,2,15,16,17,2,3,4,6,8,9]]
应该分成 [[0,1,2,15,16,17],[2,3,4,6,8,9]]