0

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

Björn
  • 1,610
  • 2
  • 17
  • 37
  • Hi Thanks, this question was kinda helpfull. However, the main difference is that the author in the first question, had only 1 range to search in and knew already that all intervalls are inside that range. In my case I have not one range but multiple ranges, where the intervalls can start before the range, in the middle of it, or after it. Does that qualify as a new question? – Björn Aug 09 '18 at 17:51
  • I've found a solution :) – Björn Aug 09 '18 at 19:55

0 Answers0