0
0
Pythonprogramming~20 mins

Nested dictionaries in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Nested Dictionary Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
Output of nested dictionary access
What is the output of this Python code?
Python
data = {'team': {'leader': 'Alice', 'members': 5}}
print(data['team']['leader'])
A"team"
BKeyError
C5
DAlice
Attempts:
2 left
๐Ÿ’ก Hint
Look inside the nested dictionary under the key 'team'.
โ“ Predict Output
intermediate
2:00remaining
Length of nested dictionary
What is the output of this code?
Python
info = {'person': {'name': 'Bob', 'age': 30}, 'job': {'title': 'Engineer', 'years': 5}}
print(len(info['person']))
A2
B4
C1
DTypeError
Attempts:
2 left
๐Ÿ’ก Hint
Count the keys inside the nested dictionary under 'person'.
๐Ÿง  Conceptual
advanced
2:00remaining
Understanding nested dictionary update
What will be the value of data after running this code?
Python
data = {'outer': {'inner': 10}}
data['outer']['inner'] += 5
A{'outer': {'inner': 15}}
B{'outer': {'inner': 5}}
C{'outer': {'inner': 10}}
DTypeError
Attempts:
2 left
๐Ÿ’ก Hint
The += operator adds 5 to the current value.
โ“ Predict Output
advanced
2:00remaining
Accessing missing nested key error
What error does this code raise?
Python
d = {'a': {'b': 1}}
print(d['a']['c'])
ANo error, prints None
BKeyError
CIndexError
DTypeError
Attempts:
2 left
๐Ÿ’ก Hint
Check if the key 'c' exists inside the nested dictionary.
๐Ÿš€ Application
expert
3:00remaining
Count total keys in nested dictionary
What is the total number of keys in all levels of this nested dictionary?
Python
nested = {'x': {'y': {'z': 1}}, 'a': 2, 'b': {'c': 3, 'd': 4}}
A4
B6
C7
D5
Attempts:
2 left
๐Ÿ’ก Hint
Count keys at every level: top-level and nested inside.