I've got 2 ranges for which I want to get the overlap. And in a second step remove that overlap from the first range.
Currently the ranges are saved in a list, that has the form of (start value, end value).
So Range 1 be:
(5230,7585)
And Range 2 be:
(6752,6988)
Is this best possible solution for this, to create variables in which I call the range function like this and compare these like descriped elsewhere (How to find range overlap in python?)
x = range(5230,7585)
y = range(6752,6988)
xs = set(x)
xs.intersection(y)
Actually I got >30.000 entry in both type of ranges. I am interested in finding the ranges from List 2 (or Ranges 2) that overlap with these of List 1 (Ranges 1). The intersections of List 2 with List 1 shall then be removed from List 1. So that List 1 Look like this
List1 = [...,[5230,6752], [6988,7585], ...]
I tried to do it with a lot of for loops and if statements but it soon got really confusing and unclear. I can post my code this far, however I am not sure that this would help. Is there a library or built-in function that can realize this task better (than manually via for-if-statements). What is the most pythonic way to remove the intersection.
would it be?
xintrm = xs.difference(y)
Best Regards,
Edit 1: Hey thanks @ the moderator. I am having trouble with transfering the solutions suggested in the other thread to my situation. Since I dont have just one range in which I want to finde the intervals but instead I have multiple ranges to search for intercepts