Don't know how to name such pattern, but by examples I think it is easier to explain.
For example let say I have this list:
lst = [1, 2, 3, 5, 6, 7, 8, 10, 11, 15]
So Now I need to merge part of list that goes by increment of one (meaning only first and last items ar kept), but if there only two items in such increment, there is nothing to merge, because they are both first and last items of such pattern.
So by running some method that handles this, it should separate it in this:
merged = [(1, 3), (5, 8)]
original = [10, 11, 15]
Note on original list. It has those three items only, because 2
, 6
and 7
are merged (they match that pattern). 10
and 11
goes by one increment, but there are only two numbers, so there is nothing to merge. And 15
does not match any pattern at all.
I thought of using some comparison of first and second items on iteration, but algorithm got complicated and I was not able to properly merge/detach those items.
P.S.
And the reason for this is I have a module that generates excel reports. And it is possible to specify formulas how some rows need to be computed (on excel side).
Now current functionality returns specific (when separate part of sheet are used in one formula) rows numbers. So for example formula could end up something like: "sum(A1, A2, A3, A5)"
. And if there lots of rows, actual expression could become very big. But if I could simplify it by having that same formula for exmaple "sum(A1:A3, A5)"
it would not be so big.