Question: Hi, Could you please explain the code in red box below in plain English? Thanks. Exercise 5 (grades_by_assignment_test: 2 points). Write some code to compute
Hi,
Could you please explain the code in red box below in plain English? Thanks.

Exercise 5 (grades_by_assignment_test: 2 points). Write some code to compute a dictionary named grades_by_assignment, whose keys are assignment (exam) names and whose values are lists of scores over all students on that assignment. For instance, grades_by_assignment [ ' Exam 1' ] == [100, 88, 45, 59, 73, 89]. In [12 ] : Student's answer (Top) # One-Line solution: It works, and is vaguely clever, but it is not pretty. #grades_by_assignment = fa: [int(L[k]) for L in grades[1: ]] for k, a in zip(range(1, 4), assig nments ) } # Alternative: More verbose but (arguably ) more readable grades_by_assignment = {} # Empty dictionary for k, a in enumerate (assignments ) : # (0, 'Exam 1' ) , ... grades_by_assignment [a] = [int(L[k+1]) for L in grades[1: ]] In [13] : Grade cell: grades_by_assignment_test Score: 2.0 / 2.0 (Top) # `grades_by_assignment_test : Test cell print (grades_by_assignment) assert type (grades_by_assignment ) is dict, "Output is not a dictionary." assert len(grades_by_assignment) == 3, "Wrong number of assignments." assert grades_by_assignment [ ' Exam 1' ] == [100, 88, 45, 59, 73, 89], 'Wrong grades list' assert grades_by_assignment [ ' Exam 3' ] == [80, 111, 67, 67, 83, 101], 'Wrong grades list' assert grades_by_assignment [ ' Exam 2' ] == [90, 99, 56, 61, 79, 97], 'Wrong grades list' print("\ (Passed! )") { 'Exam 1' : [100, 88, 45, 59, 73, 89], 'Exam 3': [80, 111, 67, 67, 83, 101], 'Exam 2': [90, 99, 5 6, 61, 79, 97]} (Passed! )
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
