python return lists of continuous integers from list
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: continuous_integers = [[0,1,2,3], [10,11,12], [59]] I have the following which works, but seems like a poor way to do it: sub_list = [] continuous_list = [] for x in full_list: if sub_list == []: sub_list.append(x) elif x-1 in sub_list: sub_list.append(x) else: continuous_list.append(sub_list) sub_list = [x] continuous_list.append(sub_list) I've seen other questions suggesting that itertools.groupby is an efficient way to do this, but I