【发布时间】:2017-08-03 04:08:23
【问题描述】:
所以我写了这个来检测数字(时间)之间的重叠并且它工作正常,现在我想添加检查它是否在一周中的同一天但是当我尝试添加这个条件时没有打印任何内容。
intervals = [[100,200, "M", "math"],[100,200, "T", "calc"], [150,250, "M", "eng"],[300,400, "W", "design"], [50,250, "T", "bio"]]
# s = start e = end d = day
overlapping = [ [s,e,d] for s in intervals for e in intervals for d in intervals if s is not e and s[1]>e[0] and s[0]<e[0] and d[1] == d[0] or s[0]==e[0] and s[1]==e[1] and d[1] == d[0] and s is not e]
for x in overlapping:
print '{0} overlaps with {1}'.format(x[0],x[1])
'''
expected:
[100,200, "M", "math"] overlaps with [150,250, "M", "eng"]
[100,200, "T", "calc"] overlaps with [50,250, "T", "bio"]
'''
知道我的逻辑有什么问题吗?
【问题讨论】:
标签: python python-2.7 logic