0
0
Pythonprogramming~20 mins

Why dictionaries are used in Python - Challenge Your Understanding

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!
๐Ÿง  Conceptual
intermediate
2:00remaining
Why use dictionaries for fast data lookup?
Dictionaries in Python store data as key-value pairs. Why are they preferred for fast data lookup compared to lists?
ABecause dictionaries use keys to access values directly, making lookup faster than searching through a list.
BBecause dictionaries store data in order, so they are faster to search than lists.
CBecause dictionaries use less memory than lists, making them faster.
DBecause dictionaries automatically sort data, making lookup faster.
Attempts:
2 left
๐Ÿ’ก Hint
Think about how you find a phone number in a phone book versus a list of names.
โ“ Predict Output
intermediate
1:30remaining
Output of dictionary key access
What is the output of this code?
Python
person = {'name': 'Alice', 'age': 30}
print(person['age'])
AAlice
B30
C'age'
DKeyError
Attempts:
2 left
๐Ÿ’ก Hint
The key 'age' is used to get the value from the dictionary.
โ“ Predict Output
advanced
1:30remaining
What happens when accessing a missing key?
What error does this code raise?
Python
data = {'x': 10, 'y': 20}
print(data['z'])
AKeyError
BIndexError
CTypeError
DValueError
Attempts:
2 left
๐Ÿ’ก Hint
The key 'z' does not exist in the dictionary.
๐Ÿง  Conceptual
advanced
2:00remaining
Why dictionaries are useful for grouping related data?
Which reason best explains why dictionaries are used to group related data?
ABecause dictionaries automatically sort data alphabetically.
BBecause dictionaries use less memory than lists.
CBecause dictionaries only store numbers, making calculations faster.
DBecause dictionaries allow storing data with meaningful keys, making it easy to understand and access specific values.
Attempts:
2 left
๐Ÿ’ก Hint
Think about how you label things in real life to find them easily.
โ“ Predict Output
expert
2:00remaining
Number of items in a nested dictionary
What is the number of items in the dictionary after this code runs?
Python
inventory = {'fruits': {'apple': 10, 'banana': 5}, 'vegetables': {'carrot': 7}}
print(len(inventory))
A5
B3
C2
D7
Attempts:
2 left
๐Ÿ’ก Hint
len() counts only the top-level keys in the dictionary.