0
0
Pythonprogramming~5 mins

Dictionary use cases in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AList
BDictionary
CTuple
DSet
How do you add a new key-value pair to a dictionary?
Adict.insert(key, value)
Bdict.add(key, value)
Cdict.append(key, value)
Ddict[key] = value
What happens if you use a key that already exists in a dictionary when assigning a value?
AThe key is duplicated
BAn error is raised
CThe old value is replaced with the new value
DThe dictionary ignores the new value
Which of these is NOT a typical use case for dictionaries?
AStoring ordered sequences
BCaching results
CMapping keys to values
DCounting items
How can dictionaries help group items by category?
AUse categories as keys and lists of items as values
BUse items as keys and categories as values
CUse lists inside keys
DDictionaries cannot group items
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.