Answer to Question #298537 in Python for Sudheer

Question #298537

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

1
Expert's answer
2022-02-16T10:21:14-0500
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))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Sudheer
16.02.22, 17:24

Tnank you very much...

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS