I am trying to find one or multiple ranges of values within a list in the most efficient way.
My list-attribute looks like this: (1, 2, 3, 5, 6, 7, 9, 12,13,14,15,16).
I would like to end up with the following result: (1-3, 5-7, 9,12-16).
Is there an efficient way to do this without coding? Maybe using the variable setter?
Since I am using only positive integers, my current way consists of adding 1 and substracting 1 to each value, then using mergers to find out, if the corresponding next value upwards or downwards exists, and then dividing my values into classes:
- values that were not assigned the next upper or lower value --> keep as single value
- values that were assigned upper only --> keep as lower value
- values that were assigned lower only --> keep as upper value
- values that have both --> ditch.