write a python function Top_Price(A) (Refer RollNo_W9A_2.py ) which takes a dictionary containing all items with their prices and return a string containing top-3 item names and their prices
def Top_Price(A:dict) -> str:
sorted_items = sorted(A, key=A.get, reverse=True)
res = ""
for item in sorted_items[:3]:
res += f"{item}: {A[item]}\n"
return res
test_dict = {
"item3": 60,
"item2": 70,
"item4": 15,
"item5": 10,
"item1": 100,}
print(Top_Price(test_dict))
Comments
Tnank you very much...
Leave a comment