0

How to print the highest from the dictionary attached

students = {'John': 53, 'Ann':62, 'Peter':45, 'Tom':62} def largest(students): theLargest = students[i] for i in range(1, len(students)): if theLargest < students[i]: theLargest = students[i] return theLargest largest() highest = max(students, key=students.get) print (highest, students[highest])

14th May 2020, 12:25 PM
SWL
3 Respuestas
+ 5
You can simply do this a=max(students.values()) for i,j in students.items(): if j==a: print(i,j)
14th May 2020, 12:34 PM
Abhay
Abhay - avatar
+ 1
What about if more than one key holds the same max value? "Ann" nad "Tom" both have 62. Normally the program should show both of them? Abhya, your code does cover this!
14th May 2020, 2:07 PM
Lothar
Lothar - avatar