Generation

generate functionTue, 14 Feb 2023

check that a series of time periods in a weekly schedule don't overlap

def overlaps(periods): sorted_by_lower_bound = sorted(periods, key=lambda tup: tup[0]) for higher in sorted_by_lower_bound: for lower in sorted_by_lower_bound: if higher[0] < lower[1] and higher != lower: return True return False overlaps([(1, 3), (2, 4), (4, 5)])

Questions about programming?Chat with your personal AI assistant