Programming Assignment Unit 7
Programming Assignment Unit 7
By
Supervised By
Dr Vikas Thada
Instructor, Department of Computer Science
University of the People
January 4, 2024
For each course in the list of courses for a student, the function checks whether the course is
already a key in the inverted_dict. If the course is already a key, it appends the current student to
the list of values for that key, but with a constraint: each key can have a maximum of three
values (students). This ensures that the teacher gets exactly three students for each course.
If the course is not a key, it creates a new key with the course and sets the value as a list
containing the current student. This process continues until the inverted dictionary is fully
constructed.
The sample input provided includes two students ('Stud1' and 'Stud2') with their respective
courses. The output demonstrates the inverted dictionary, satisfying the teacher's requirement,
with courses as keys and three students enrolled in each course as values (or fewer if there are
not enough students).
Word Count – 240 words
(Allen Downey, 2015)
References
Allen Downey, J. E. (2015). How to Think Like a Computer Scientist. In A. Downey, Think Python. 9
Washburn Ave, Needham MA 02492: Green Tea Press.
kjdElectronics. (2017, August 5). Python beginner tutorial 8 - For loop, lists, and dictionaries [Video].
YouTube. https://youtu.be/bE6mSBNp4YU