Module Overview
Python Dictionaries
Lists keep things in order, indexed by position. This module covers Python’s other core collection: the dictionary, which stores data as key-value pairs, along with two related collection types: tuples and sets.
Why This Matters
Real data rarely comes as a flat, ordered list. It’s usually labeled: a username mapped to a profile, a product mapped to a price. A list only lets you look things up by position:
prices = [1.99, 2.49, 3.99]
prices[0] # 1.99, but what does that even belong to?
A dictionary labels each value with a key, so you look things up by what they are, not where they sit in the collection:
prices = {"apple": 1.99, "banana": 2.49, "bread": 3.99}
prices["banana"] # 2.49
Dictionaries are how Python represents that kind of labeled data, and you’ll use them constantly alongside lists.
What You’ll Learn
- How to create, read, and modify a dictionary
- The built-in methods for working with dictionary keys and values
- How to loop over a dictionary and use dictionary comprehension
- Tuples (immutable collections) and sets (unordered, unique collections)
Outcome
By the end of this module, you’ll be comfortable choosing between lists, dictionaries, tuples, and sets depending on what a problem actually calls for.
Let’s get started.