Recall & Review
beginner
What is a dictionary in Python?
A dictionary is a collection of key-value pairs where each key is unique and used to access its corresponding value.
Click to reveal answer
beginner
How do you create an empty dictionary in Python?
You create an empty dictionary using curly braces:
{} or the dict() function.Click to reveal answer
beginner
Create a dictionary with keys 'name' and 'age' and values 'Alice' and 30.
Use
{'name': 'Alice', 'age': 30} to create the dictionary.Click to reveal answer
intermediate
Can dictionary keys be mutable types like lists?
No, dictionary keys must be immutable types like strings, numbers, or tuples. Lists cannot be keys because they can change.
Click to reveal answer
intermediate
What happens if you create a dictionary with duplicate keys?
The last value for the duplicate key will overwrite previous ones, so only the last key-value pair remains.
Click to reveal answer
Which of these is the correct way to create a dictionary with keys 'a' and 'b' and values 1 and 2?
✗ Incorrect
Dictionaries use curly braces with key-value pairs separated by colons.
What is the output of
type({}) in Python?✗ Incorrect
Empty curly braces create an empty dictionary of type dict.
Which of these can be used as a dictionary key?
✗ Incorrect
Tuples are immutable and can be dictionary keys; lists and dictionaries cannot.
What will be the value of key 'x' after this dictionary is created?
{'x': 1, 'x': 2}✗ Incorrect
Duplicate keys keep the last assigned value, so 'x' will have value 2.
How do you create an empty dictionary using a function?
✗ Incorrect
The dict() function creates an empty dictionary.
Explain how to create a dictionary in Python and what rules apply to keys.
Think about how you store labeled information and what can be used as labels.
You got /3 concepts.
Describe what happens if you use duplicate keys when creating a dictionary.
Consider what happens if you write the same label twice on a list of notes.
You got /3 concepts.