Editor

Loop Through a Dictionary

Beginner · Write the code · from Python Dictionaries: The Complete Guide with Real Examples

From the lesson: Python Dictionaries: The Complete Guide with Real Examples

Open the contacts app on your phone. You look up a person by name and get their phone number. You don't search by position - you don't say "give me contact number 47." You search by name.

Read the lesson

Loop through the dictionary and print each fruit and its price in this format:

apple: $1.50
banana: $0.75
cherry: $3.00

Make sure prices show exactly two decimal places.

prices = {'apple': 1.5, 'banana': 0.75, 'cherry': 3.0}
# Loop and print each item

More Dictionaries exercises

All Python exercises · 50 practice problems · Data Structures quiz