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])
3 Respuestas
+ 5
You can simply do this
a=max(students.values())
for i,j in students.items():
if j==a:
print(i,j)
+ 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!