Press "Enter" to skip to content

Python Program Example to Get Minimum and Maximum Value from Dictionary

Below is a Python program example to get minimum and maximum value from a Dictionary object.

Python: Get Minimum and Maximum Value from a Dictionary Example

In the following example, it will invert the keys and values of the dictionary object using the zip() method and will get the minimum and maximum values using the min() and max() methods. It also uses the sorted() to print the values of a dictionary in order.

prices = {
   'APPLE': 45.23,
   'ORANGE': 612.78,
   'MANGO': 205.55,
   'BLUEBERRY': 37.20,
   'STRAWBERRY': 10.75

# Find min and max price
min_price = min(zip(prices.values(), prices.keys()))
max_price = max(zip(prices.values(), prices.keys()))

print('min price:', min_price)
print('max price:', max_price)

print('sorted prices:')
prices_sorted = sorted(zip(prices.values(), prices.keys()))
for price, name in prices_sorted:
    print('    ', name, price)


min price: (10.75, 'STRAWBERRY')
max price: (612.78, 'ORANGE')
sorted prices:
     STRAWBERRY 10.75
     BLUEBERRY 37.2
     APPLE 45.23
     MANGO 205.55
     ORANGE 612.78

Related tutorials:

Reference: Python Functions Manual

Vinish Kapoor

Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

Comments are closed.