Predict the Output: Duplicate Keys
Beginner · Predict the output · 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 lessonRead this code carefully and predict what it will print. What happens when a dictionary has duplicate keys?
Type the exact output.
data = {'a': 1, 'b': 2, 'a': 3}
print(data)
print(len(data))
More Dictionaries exercises
- Create a Dictionary and Access a ValueBeginner
- Add and Modify Dictionary EntriesBeginner
- Safe Access with get()Beginner
- Loop Through a DictionaryBeginner
- Fix the Bug: Checking for a ValueIntermediate
- Build a Word CounterIntermediate
- Access Nested Dictionary DataIntermediate
All Python exercises · 50 practice problems · Data Structures quiz