0
0
Pythonprogramming~20 mins

Dictionary use cases in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Dictionary Mastery
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 = {'user': {'name': 'Alice', 'age': 30}, 'active': True}
print(data['user']['age'])
A30
B'Alice'
CTrue
DKeyError
Attempts:
2 left
๐Ÿ’ก Hint
Look inside the nested dictionary under 'user' key.
๐Ÿง  Conceptual
intermediate
1:30remaining
Dictionary keys uniqueness
Which statement about Python dictionary keys is true?
ADictionary keys can be duplicated if values differ.
BDictionary keys must be unique and immutable.
CDictionary keys can be mutable types like lists.
DDictionary keys can be any data type including functions.
Attempts:
2 left
๐Ÿ’ก Hint
Think about what happens if you try to use a list as a key.
๐Ÿ”ง Debug
advanced
2:00remaining
Identify the error in dictionary update
What error does this code raise?
Python
d = {'a': 1, 'b': 2}
d.update(['c', 3])
ANo error, dictionary updated
BKeyError
CValueError
DTypeError
Attempts:
2 left
๐Ÿ’ก Hint
Check the argument type for update method.
โ“ Predict Output
advanced
1:30remaining
Result of dictionary comprehension with condition
What is the output of this code?
Python
result = {x: x**2 for x in range(5) if x % 2 == 0}
print(result)
A{0: 0, 2: 4, 4: 16}
B{1: 1, 3: 9}
CSyntaxError
D{0: 0, 1: 1, 2: 4, 3: 9, 4: 16}
Attempts:
2 left
๐Ÿ’ก Hint
Only even numbers are included as keys.
๐Ÿš€ Application
expert
2:30remaining
Count character frequency in string using dictionary
What is the value of 'freq' after running this code?
Python
text = 'banana'
freq = {}
for ch in text:
    freq[ch] = freq.get(ch, 0) + 1
print(freq)
A{'b': 1, 'a': 3, 'n': 2}
B{'b': 1, 'a': 2, 'n': 3}
C{'b': 1, 'a': 3, 'n': 3}
DKeyError
Attempts:
2 left
๐Ÿ’ก Hint
Count how many times each letter appears in 'banana'.