I have two lists of the form:
lst1 = [(1.2, 4), (5, 8), (19, 21), (24.5, 26)]
lst2 = [(1, 3), (6.55, 14.871), (22, 23)]
The output I am looking to get is:
output = [(1.2, 3), (6.55, 8)]
Basically, I want the intersections between the ranges defined by the tuples across the two lists.
You can assume-
the indices to be ordered within a given list. For example, in lst2:
1 < 6.55 < 22the ranges to be valid (within a tuple, the startVal<=endEndVal). In lst2:
1 < 3 and 6.55 < 14.871 and 22 < 23
What is an efficient way to achieve this?