Suppose i have to following list, it is guaranteed to be sorted and have no duplicates:
In [224]: a=[0,2,4,8,12,16,20,21,30,33,36]
I want to subdivide it to form a nested tuple in which each item can be created using range or np.arange. There can sometimes be numerous grouping possibilities (two items can always form a group). I want to minimize the amount of groups containing two items.
Here is an example:
In [225]: to_range_group(a)
((0,2,4),(8,12,16,20),(21),(30,33,36))
What is the most pythonic and efficient way to accomplish this?