Dremendo Tag Line

Print highest value from a dictionary in Python

Dictionaries - Question 7

In this question, we will see how to print the subject having maximum mark from a given dictionary in Python programming. To know more about dictionaries click on the dictionaries lesson.

A dictionary is given below as:

    a={'english':56, 'maths':84, 'physics':92, 'computer':95, 'history':87, 'geography':64}

Q7) Write a program in Python to print the subject having maximum mark from the dictionary a. The output should be:

    computer = 95

Program

a={'english':56, 'maths':84, 'physics':92, 'computer':95, 'history':87, 'geography':64}

print('dictionary a:',a)
m=max(a.values())

for key in a:
    if a[key]==m:
        print(key,"=",a[key])
        break

Output

dictionary a: {'english': 56, 'maths': 84, 'physics': 92, 'computer': 95, 'history': 87, 'geography': 64}
computer = 95
video-poster