Learn Without Walls
← Back to Module 8

Study Guide: Dictionaries & Tuples

Module 8 Review Materials

Key Terms

Dictionary (dict): A mutable collection of key-value pairs enclosed in curly braces {}.
Key: An immutable identifier used to look up a value in a dictionary. Must be unique.
Value: The data associated with a key. Can be any Python type.
Key-Value Pair: A single entry in a dictionary, written as key: value.
KeyError: The error Python raises when you try to access a dictionary key that does not exist.
Tuple: An ordered, immutable sequence created with parentheses () or commas.
Immutable: Cannot be changed after creation. Tuples and strings are immutable; lists and dictionaries are mutable.
Tuple Unpacking: Assigning each element of a tuple to a separate variable in one statement.
View Object: A dynamic object returned by keys(), values(), or items() that reflects changes to the dictionary.
Nested Dictionary: A dictionary where one or more values are themselves dictionaries.

Lesson 1: Creating and Using Dictionaries

Key Concepts

Lesson 2: Dictionary Methods

Key Concepts

Lesson 3: Tuples and Immutability

Key Concepts

Lesson 4: Choosing Data Structures

Key Concepts

Common Mistakes to Avoid

Review Questions

  1. What is the difference between d["key"] and d.get("key")?
  2. Name three types that can be used as dictionary keys.
  3. How do you loop through both keys and values of a dictionary?
  4. What is tuple unpacking? Give an example.
  5. Why would you choose a tuple over a list?
  6. How do you create a single-element tuple?
  7. What method would you use to merge two dictionaries?
  8. Can a dictionary value be a list? Can a dictionary key be a list?
  9. What data structure would you use for an address book? Why?
  10. How do you swap two variables using tuple unpacking?
Take the Quiz Back to Module 8