0

How can we find the name of the student with highest percentage( in 4 subjects) using a dictionary? We have to calculate the percentage also.

n = int(input())
student_marks = {}
for _ in range(n):
    name, *line = input().split()
    scores = list(map(float, line))
    student_marks[name] = scores
    total_marks = sum(student_marks[name])
    average_marks = total_marks/4 
    print(average_marks)

With this code I can get the percentage of each student but how to get the name of the student with maximum percentage?

vhvg vhcc
  • 19
  • 1
  • 5

1 Answers1

1

Using a list comprehension:

[y for y,w in student_marks.items() if w == [max(z for x in student_marks.values() for z in x)]][0]
Wasif
  • 14,755
  • 3
  • 14
  • 34