Monday, 10 January 2022

To print the highest and lowest values in the dictionary

 


Write a Python program to get the maximum and minimum value in a dictionary.

Sample Solution:-

Python Code:

my_dict = {'x':500, 'y':5874, 'z': 560}

key_max = max(my_dict.keys(), key=(lambda k: my_dict[k]))
key_min = min(my_dict.keys(), key=(lambda k: my_dict[k]))

print('Maximum Value: ',my_dict[key_max])
print('Minimum Value: ',my_dict[key_min])

Sample Output:

Maximum Value:  5874                                                                                          
Minimum Value:  500

No comments:

Post a Comment