Recall & Review
beginner
What is a dictionary in Python?
A dictionary is a collection of key-value pairs where each key is unique. It allows fast lookup, insertion, and deletion of values based on keys.
Click to reveal answer
beginner
How can dictionaries be used to count occurrences of items?
You can use a dictionary to store items as keys and their counts as values. Each time an item appears, increase its count in the dictionary.
Click to reveal answer
beginner
Why are dictionaries useful for representing real-world data like a phone book?
Dictionaries map unique keys (like names) to values (like phone numbers), making it easy to find a phone number by name quickly.
Click to reveal answer
intermediate
How can dictionaries help in grouping data?
Dictionaries can group data by using keys as group names and values as lists of items belonging to each group.
Click to reveal answer
intermediate
What is a common use of dictionaries in caching?
Dictionaries store results of expensive computations with input parameters as keys, so repeated calls can return cached results quickly.
Click to reveal answer
Which data structure is best for fast lookup by a unique key?
✗ Incorrect
Dictionaries provide fast lookup by unique keys, unlike lists or tuples which require searching.
How do you add a new key-value pair to a dictionary?
✗ Incorrect
You add or update a key-value pair by assigning value to dict[key].
What happens if you use a key that already exists in a dictionary when assigning a value?
✗ Incorrect
Assigning a value to an existing key updates the value, replacing the old one.
Which of these is NOT a typical use case for dictionaries?
✗ Incorrect
Dictionaries do not store ordered sequences; lists or tuples are better for that.
How can dictionaries help group items by category?
✗ Incorrect
Grouping is done by using category names as keys and storing lists of items as values.
Explain three common use cases for dictionaries in Python.
Think about how dictionaries store data and how that helps in real-life tasks.
You got /4 concepts.
Describe how you would use a dictionary to count how many times each word appears in a list.
Imagine tallying votes or scores using a dictionary.
You got /3 concepts.