The Dict: One Key, One Value, Zero Guessing
The problem...
You have a list of soldiers and a list of scores.
names = ["Raven", "Wolf", "Ghost"]
scores = [85, 74, 91]
To find Wolf's score, you need to know Wolf is at index 1. Then look up index 1 in scores.
That's two steps. And it breaks the moment the lists get out of sync.
There's a better way.
The idea!
A dictionary stores values under names — not positions.
Instead of "the score at index 1", you ask for "Wolf's score".
Direct. No counting. No index math.
Making it real
Think of it like a real dictionary. You look up a word — you get its definition.
In Python: you look up a key — you get its value.
Every entry is a pair. Key and value, always together.
In practice
scores = {"Raven": 85, "Wolf": 74, "Ghost": 91}
print(scores["Wolf"])
Output → 74
You asked for "Wolf". Python went directly to it. No index. No loop.
The full picture
scores = {
"Raven": 85,
"Wolf": 74,
"Ghost": 91
}
- Curly braces
{}create a dict - A colon
:separates each key from its value - Entries are separated by commas
- Keys are usually strings — values can be anything
Going further
A dict can hold any type of value — strings, integers, floats, lists, even other dicts.
soldier = {
"name": "Raven",
"score": 85,
"active": True,
"gear": ["rifle", "vest", "radio"]
}
One dict. One soldier. All their data in one place.
What's really happening
A dict doesn't store values in a sequence. It stores them behind keys.
When you look up a key, Python finds the value instantly — it doesn't scan from the top.
That's why dicts are fast. And that's why they exist.
Heads up!
- Keys must be unique — if you use the same key twice, the second value overwrites the first
- Keys are case-sensitive —
"Wolf"and"wolf"are different keys - Looking up a key that doesn't exist raises a
KeyError - Dicts are ordered — Python keeps keys in the order you added them
The mindset shift
Stop thinking: "What index is this value at?"
Start thinking: "What key does this value belong to?"
What you should understand now
- A dict stores values under keys — not positions
- Curly braces, colon between key and value, commas between entries
- You look up values by key — direct, no index math
- Keys are unique — values can be anything
- Dicts are ordered and fast