In this python dictonary program, we will find maximum and minimum values in a dictionary.
Steps to solve the program
- Take a dictionary as input and create an empty list.
- Use for loop to iterate over values in the dictionary using values().
- Add the values to the empty list.
- Sort the list by using sort().
- Find the maximum and minimum values by using logic.
- Print the output.
dict1 = {'a':10,'b':44,'c':60,'d':25}
list1 = []
for val in dict1.values():
list1.append(val)
list1.sort()
print("Minimum value: ",list1[0])
print("Maximum value: ",list1[-1])
Output :
Minimum value: 10
Maximum value: 60