I have a numerical list :
numlist = [601, 601, 601, 602, 602, 603, 1245, 1245, 1245, 1245, 1247, 1249, 1250,602,602]
This list will always be "sorted" like shown, with values restarting after a certain point.
In that list, I need to group and count the number of identical values, and add to the count the next item IF it's numerical value is one (and only one) more than the preceding item.
Expected result :
>>>result
[6,4,1,2,2]
I can do :
>>>from itertools import groupby
>>>[len(list(group)) for key, group in groupby(numlist)]
[3, 2, 1, 4, 1, 1, 1, 2]
which count the number of identical values, but how to also include in the groups values as described above ?
More explanation :
Go through the list, if next item is the same value or same value +1, group them.