I'm trying to return the student name and the sum of their points for the student with the highest total of points. I have my code below.
Code:
# student_grades contains scores (out of 100) for 5 assignments
student_grades = {
'Andrew': [56, 79, 90, 22, 50],
'Nisreen': [88, 62, 68, 75, 78],
'Alan': [95, 88, 92, 85, 85],
'Chang': [76, 88, 85, 82, 90],
'Tricia': [99, 92, 95, 89, 99]
}
# calculate the top student and their total points
list_of_student_grades = list(student_grades.items())
top_student = tuple([(name, sum(grades)) for (name, grades) in list_of_student_grades if
sum(grades) == max([sum(grades) for name, grades in list_of_student_grades])])
print(list_of_student_grades)
print(top_student)
Output:
[('Andrew', [56, 79, 90, 22, 50]), ('Nisreen', [88, 62, 68, 75, 78]), ('Alan', [95, 88, 92, 85, 85]), ('Chang', [76, 88, 85, 82, 90]), ('Tricia', [99, 92, 95, 89, 99])]
(('Tricia', 474),)
I have two questions... First, why is the output not just ('Tricia', 474) (why the extra comma and set of parenthesis)? Second, is there a better way to go about this?
Thank you in advance!