Fix indentation

This commit is contained in:
MstrPikachu
2021-10-03 14:28:20 -04:00
parent c4bda0c54c
commit 3194ba1547
+55 -55
View File
@@ -156,74 +156,74 @@ def possible_schedules(c1: tuple[str, str, set], c2: tuple[str, str, set]) \
""" """
return [{c1[0]: section1, c2[0]: section2} for section1 in c1[2] for section2 in c2[2]] 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]) \
-> list[dict[str, tuple[str, str, tuple]]]: -> list[dict[str, tuple[str, str, tuple]]]:
"""Return a list of all VALID schedules of courses c1 and c2. """Return a list of all VALID schedules of courses c1 and c2.
Each returned schedule should contain exactly two key-value pairs, one with the course Each returned schedule should contain exactly two key-value pairs, one with the course
code and a section of c1, and the other with the course code and a section of c2. code and a section of c1, and the other with the course code and a section of c2.
Invalid schedules are NOT returned in this list. Invalid schedules are NOT returned in this list.
Hint: Hint:
- Use is_valid - Use is_valid
- Use possible_schedules - Use possible_schedules
Preconditions: Preconditions:
- 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) schedules = possible_schedules(c1, c2)
return [x for x in schedules if is_valid(x)] 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],
c3: tuple[str, str, set], c3: tuple[str, str, set],
c4: tuple[str, str, set], c4: tuple[str, str, set],
c5: tuple[str, str, set]) -> list[dict[str, tuple]]: c5: tuple[str, str, set]) -> list[dict[str, tuple]]:
"""Return a list of every possible schedule that contains all given courses. """Return a list of every possible schedule that contains all given courses.
This is analogous to possible_schedules, except now there are 5 courses instead of 2. This is analogous to possible_schedules, except now there are 5 courses instead of 2.
If a given course has no sections, then return an empty list. If a given course has no sections, then return an empty list.
(This will happen "automatically" if you use a comprehension with an empty collection!) (This will happen "automatically" if you use a comprehension with an empty collection!)
Preconditions: Preconditions:
- all given courses match the format for a course described by the assignment handout. - all given courses match the format for a course described by the assignment handout.
- c1 != c2 and c1 != c3 and c1 != c4 and c1 != c5 - c1 != c2 and c1 != c3 and c1 != c4 and c1 != c5
- c2 != c3 and c2 != c4 and c2 != c5 - c2 != c3 and c2 != c4 and c2 != c5
- c3 != c4 and c3 != c5 - c3 != c4 and c3 != c5
- c4 != c5 - c4 != c5
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 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]] 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],
c3: tuple[str, str, set], c3: tuple[str, str, set],
c4: tuple[str, str, set], c4: tuple[str, str, set],
c5: tuple[str, str, set]) -> list[dict[str, tuple]]: c5: tuple[str, str, set]) -> list[dict[str, tuple]]:
"""Return a list of every valid schedule that contains all given courses. """Return a list of every valid schedule that contains all given courses.
This is analogous to valid_schedules, except now there are 5 courses instead of 2. This is analogous to valid_schedules, except now there are 5 courses instead of 2.
Hint: Hint:
- Use is_valid - Use is_valid
- Use possible_five_course_schedules - Use possible_five_course_schedules
Preconditions: Preconditions:
- all given courses match the format for a course described by the assignment handout. - all given courses match the format for a course described by the assignment handout.
- c1 != c2 and c1 != c3 and c1 != c4 and c1 != c5 - c1 != c2 and c1 != c3 and c1 != c4 and c1 != c5
- c2 != c3 and c2 != c4 and c2 != c5 - c2 != c3 and c2 != c4 and c2 != c5
- c3 != c4 and c3 != c5 - c3 != c4 and c3 != c5
- c4 != c5 - c4 != c5
""" """
schedules = possible_five_course_schedules(c1, c2, c3, c4, c5) schedules = possible_five_course_schedules(c1, c2, c3, c4, c5)
return [x for x in schedules if is_valid(x)] return [x for x in schedules if is_valid(x)]
################################################################################################### ###################################################################################################