Checking for overlap between time spans

后端 未结 5 2198
别跟我提以往
别跟我提以往 2021-01-06 01:23

I have a list of time entries (HHMM format) with a start time and a stop. I\'m having trouble figuring out how to code it in Python where it returns if there\'s an overlap o

5条回答
  •  余生分开走
    2021-01-06 02:13

    Assuming you have an intervals_overlap(interval1, interval2) function…

    The first idea is a naive iteration over every pair of intervals in the list:

    for interval1 in intervals:
        for interval2 in intervals:
            if interval1 is not interval2:
                if intervals_overlap(interval1, interval2):
                    return True
    return False
    

    But you should be able to figure out smarter ways of dong this.

提交回复
热议问题