Product with the highest price

EasyDictionary Programs · 41 of 94

Write a Python program to find the product with the highest price.

Advertisement
Input
{"price1": 450, "price2": 600, "price3": 255, "price4": 400}
Output
price2 600

Approach

  1. max(d, key=d.get).

Solution

Python
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.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More dictionary programs

← All 94 Dictionary Programs