In Find all possible combinations that overlap by end and start, we get the following program that gets all possible combinations of ranges that only overlap by end and start values. The output is given in string format, as with the following example:
def getAllEndOverlappingIndices(lst, i, l):
r = -1
if i == len(lst):
if l:
print(l)
return
n = i + 1
while n < len(lst) and r > lst[n][0]:
n += 1
getAllEndOverlappingIndices(lst, n, l)
n = i + 1
r = lst[i][1]
while n < len(lst) and r > lst[n][0]:
n += 1
getAllEndOverlappingIndices(lst, n, l + str(lst[i]))
indices = [(0.0, 2.0), (0.0, 4.0), (2.5, 4.5), (2.0, 5.75), (2.0, 4.0), (6.0, 7.25)]
indices.sort()
print(getAllEndOverlappingIndices(indices, 0, ''))
(6.0, 7.25)
(2.5, 4.5)
(2.5, 4.5)(6.0, 7.25)
(2.0, 5.75)
(2.0, 5.75)(6.0, 7.25)
(2.0, 4.0)
(2.0, 4.0)(6.0, 7.25)
(0.0, 4.0)
(0.0, 4.0)(6.0, 7.25)
(0.0, 2.0)
(0.0, 2.0)(6.0, 7.25)
(0.0, 2.0)(2.5, 4.5)
(0.0, 2.0)(2.5, 4.5)(6.0, 7.25)
(0.0, 2.0)(2.0, 5.75)
(0.0, 2.0)(2.0, 5.75)(6.0, 7.25)
(0.0, 2.0)(2.0, 4.0)
(0.0, 2.0)(2.0, 4.0)(6.0, 7.25)
I would like to have the output of the function be a list of lists with each sublist holding the separated tuples (currently, strings of the tuples are being returned). For the example given above, the output would instead be L = [[(6.0, 7.25)], [(2.5, 4.5)], [(2.5, 4.5), (6.0, 7.25)], ..., [(0.0, 2.0), (2.0, 4.0), (6.0, 7.25)]]
. I tried creating a list at beginning of the function and appending each call of the function, but I believe I am appending strings of the tuples instead of the tuples themselves. Is it possible to change the output of this function to what I would like as described? I don't have much experience with recursion and would appreciate any tips.