Checking for overlap between time spans

后端 未结 5 2105
别跟我提以往
别跟我提以往 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:01

    To expand on @Roy's answer to include situations where something has the same time slot and you need to distinguish:

    intervals = [[100,200, "math"],[100,200, "calc"], [150,250, "eng"],[300,400, "design"],[250,500, "lit"],[10,900, "english"],[1000,12300, "prog"],[-151,32131, "hist"]]
    
    overlapping = [ [x,y] for x in intervals for y in intervals if x is not y and x[1]>y[0] and x[0]

提交回复
热议问题