I have a list of integers, and I want to generate a list containing a list of all the continuous integers.
#I have: full_list = [0,1,2,3,10,11,12,59] #I want
You can use the following recipe:
from operator import itemgetter from itertools import groupby full_list = [0,1,2,3,10,11,12,59] cont = [map(itemgetter(1), g) for k, g in groupby(enumerate(full_list), lambda (i,x):i-x)] # [[0, 1, 2, 3], [10, 11, 12], [59]]