I have a list of lists composed of tuples representing blocks of military times:
[[(1405, 1525)],[(1405,1455),(1605,1655)],[(1505,1555),(1405,1455),(1305,1355)]]
I have a function to compare the times of two tuples:
def doesOverlap(tuple1, tuple2):
#tuples each represent times for courses
#the 0 index for each tuple is a start time
#the 1 index is an end time
A=int(tuple1[0])
B=int(tuple1[1])
C=int(tuple2[0])
D=int(tuple2[1])
if A<B and B<=C and C<=D:
print(False, (A,B), (B,C))
elif C<D and D<=A and A<B:
print(False, (A,B), (B,C))
else:
print(True, (A,B), (B,C))
I need to compare the times from the nested list such that the first tuple in the first list compares to the first tuple of the second using doesOverlap. If the function returns True, the first tuple of the first list should be compared to the second tuple of the second list, and so on. If the function returns False, I need to compare the first tuple from the third list to the tuples that returned False.
I'm having trouble figuring how to call the function in that order. Any suggestions?
EDIT: Here's the exact homework problem:
This method is the first of the two greedy scheduling algorithms you will write. With this particular algorithm, you will look through your list of classes and schedule them in order from the class with the least amount of possible meeting times to the class with the most number of possible meeting times. When you find the course (which you haven’t already scheduled) with the least number of listed meeting times, start at the beginning of the list of times for that course and check each value sequentially until you find one which does not conflict with courses you have already scheduled. When you find this time, add it to the schedule and move onto the course with the next lowest number of meeting times. Continue this process until you have attempted to add a time for every course. Once you are finished, return the resulting list which contains the schedule. Note that you should not modify the Dictionary which contains all of your courses and meeting times during the course of running this method.
I need to call doesOverlap from a separate function, the function described above.