Finish Part3 Q2b

This commit is contained in:
MstrPikachu
2021-10-03 14:23:52 -04:00
parent e2be177a37
commit c4bda0c54c
+7 -3
View File
@@ -154,7 +154,7 @@ def possible_schedules(c1: tuple[str, str, set], c2: tuple[str, str, set]) \
- c1 and c2 match the format for a course described by the assignment handout. - c1 and c2 match the format for a course described by the assignment handout.
- c1 != c2 - c1 != c2
""" """
return [{c1[0]: section1, c2[0]: section2} for section1 in c1[2] for section2 in c2[2]]
def valid_schedules(c1: tuple[str, str, set], def valid_schedules(c1: tuple[str, str, set],
c2: tuple[str, str, set]) \ c2: tuple[str, str, set]) \
@@ -174,7 +174,8 @@ def valid_schedules(c1: tuple[str, str, set],
- c1 and c2 match the format for a course described by the assignment handout. - c1 and c2 match the format for a course described by the assignment handout.
- c1 != c2 - c1 != c2
""" """
schedules = possible_schedules(c1, c2)
return [x for x in schedules if is_valid(x)]
def possible_five_course_schedules(c1: tuple[str, str, set], def possible_five_course_schedules(c1: tuple[str, str, set],
c2: tuple[str, str, set], c2: tuple[str, str, set],
@@ -198,7 +199,8 @@ def possible_five_course_schedules(c1: tuple[str, str, set],
HINT: you'll want a comprehension with 5 different variables. You can split up each HINT: you'll want a comprehension with 5 different variables. You can split up each
"for ... in ..." across multiple lines to help make your code more readable. "for ... in ..." across multiple lines to help make your code more readable.
""" """
return [{c1[0]: a, c2[0]: b, c3[0]: c, c4[0]: d, c5[0]: e} for a in c1[2] for b in c2[2] for c in c3[2] for d in
c4[2] for e in c5[2]]
def valid_five_course_schedules(c1: tuple[str, str, set], def valid_five_course_schedules(c1: tuple[str, str, set],
c2: tuple[str, str, set], c2: tuple[str, str, set],
@@ -220,6 +222,8 @@ def valid_five_course_schedules(c1: tuple[str, str, set],
- c3 != c4 and c3 != c5 - c3 != c4 and c3 != c5
- c4 != c5 - c4 != c5
""" """
schedules = possible_five_course_schedules(c1, c2, c3, c4, c5)
return [x for x in schedules if is_valid(x)]
################################################################################################### ###################################################################################################