On Sunday, Sunil went to the D-Mart with his family. All the family members of Sunil buy many items as per their need. At the payment counter Sunil paid 5000 Rs. After payment Sunil came home and now, he wants to analyse the top three item he bought from the D-Mart. You need to write a python function Top_Price(A)which takes a dictionary containing all items with their prices and return a string containing top-3 item names and their prices as shown in the example
Example-1
Example-2
Input:
{'item1': 45.50, 'item2':35, 'item3': 41.30, 'item4':55, 'item5': 24}
Output:
item4-55
item1-45.5
item3-41.3
Input:
{'item1': 105.50, 'item2':325, 'item3': 411.30, 'item4':5.4, 'item5': 24.7}
Output:
Item3-411.30
Item2-325
Item1-105.50
x = {'item1': 105.50, 'item2': 325, 'item3': 411.30, 'item4': 5.4, 'item5': 24.7}
x = {k: v for k, v in sorted(x.items(), key=lambda item: item[1], reverse=True)}
for i in range(0, 3):
print(f'{list(x.keys())[i]}-{list(x.values())[i]}')
Comments
Leave a comment