Add and Modify Dictionary Entries
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 lessonA dictionary representing a book is given. Do these steps in order:
1. Change the 'year' to 2024
2. Add a new key 'genre' with the value 'fiction'
3. Print the entire dictionary
Expected output:
{'title': 'The Great Adventure', 'author': 'Jane Smith', 'year': 2024, 'genre': 'fiction'}book = {'title': 'The Great Adventure', 'author': 'Jane Smith', 'year': 2020}
# Step 1: Change the year to 2024
# Step 2: Add genre
# Step 3: Print the dictionary
More Dictionaries exercises
- Create a Dictionary and Access a ValueBeginner
- Safe Access with get()Beginner
- Loop Through a DictionaryBeginner
- Predict the Output: Duplicate KeysBeginner
- Fix the Bug: Checking for a ValueIntermediate
- Build a Word CounterIntermediate
- Access Nested Dictionary DataIntermediate
All Python exercises · 50 practice problems · Data Structures quiz