Python - Removing overlapping lists

后端 未结 5 1053
旧时难觅i
旧时难觅i 2020-12-03 14:54

Say I have a list of lists that has indexes [[start, end], [start1, end1], [start2, end2]].

Like for example :

[[0, 133], [78, 100], [25,

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 14:57

    In general, two intervals are overlapping if:

    min([upperBoundOfA, upperBoundOfB]) >= max([lowerBoundOfA, lowerBoundOfB])
    

    If this is the case, the union of those intervals is:

    (min([lowerBoundOfA, lowerBoundOfB]), max([upperBoundOfA, upperBoundOfB])
    

    Similarly, the intersection of those intervals will be:

    (min([upperBoundOfA, upperBoundOfB]), max([lowerBoundOfA, lowerBoundOfB]))
    

提交回复
热议问题