Final answer:
To get the top three items' prices in a shop, use Python's built-in functions to sort the dictionary items by values and then select the top three entries.
Step-by-step explanation:
To get the top three items' prices in a shop, you can use Python's built-in functions to sort the dictionary items by values and then select the top three entries. Here's how you can do it:
prices = {'Apple': 0.50, 'Banana': 0.20, 'Mango': 0.99, 'Coconut': 2.99, 'Pineapple': 3.99}
# Sort the dictionary items by values in descending order
sorted_prices = sorted(prices.items(), key=lambda x: x[1], reverse=True)
# Select the top three entries
top_three = sorted_prices[:3]
# Print the top three items and their prices
for item, price in top_three:
print(item, price)
The expected output for the provided sample data would be:
Pineapple 3.99
Coconut 2.99
Mango 0.99