CS 1101 Learning Journal W7
CS 1101 Learning Journal W7
and nested loops to iterate through the original dictionary's values and courses. It creates key-
value pairs in the inverted dictionary for each course, with the value being a list comprehension
that identifies students associated with the course. As a result, courses are represented as keys,
and the students enrolled in each course are represented as values. The program then prints both
This section defines a function named inverting_dictionary that takes one argument, origin_dict,
This line creates the inverted dictionary (inver_dict) using dictionary comprehension. It iterates
through each course in each list of courses in the values of the original dictionary. It generates a
key-value pair in the inverted dictionary for each course. The course is the key, and the value is a
list comprehension that searches the original dictionary for students associated with that course.
# Orginal Dictionary:
This section defines the original dictionary, with students as keys and lists of courses as values
It prints a header indicating that the following output is the original dictionary, and then prints
It calls the inverting_dictionary function with the original dictionary and stores the result in
inver_dict. It prints a header indicating that the following output is the inverted dictionary, and
https://greenteapress.com/thinkpython2/thinkpython2.pdf