Python Practice › Dictionary Programs › Program 41
Product with the highest price
Write a Python program to find the product with the highest price.
Input
{"price1": 450, "price2": 600, "price3": 255, "price4": 400}Output
price2 600
Approach
max(d, key=d.get).
Solution
d = {"price1": 450, "price2": 600, "price3": 255, "price4": 400}best = max(d, key=d.get)print(best, d[best])Output
price2 600
Note
The highest price is 600 for price2; the original sample output said 500.
Learn the concept
New to this topic? Read the lesson, then come back.