Lesson 17 of 55
PythonData Structures – Dictionaries
20 minutes
Course progress31%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 17 of 55
Python20 minutes
Keep these ideas in mind as you work through the lesson.
Dictionaries map keys to values. They’re mutable, and as of Python 3.7 they preserve insertion order.
person = {'name': 'Bob', 'age': 25}
person['city'] = 'New York'
print('Name:', person['name'])
# Iterate over items
for key, value in person.items():
print(key, ':', value)
Keys must be hashable (e.g., strings, numbers, tuples). Values can be any object.