Looping Through Dictionaries
(a.k.a. Reading Game Stats Like You’re Inspecting a Boss Before Battle)
You’ve learned how to create dictionaries.
You’ve learned how to access and change values.
Now it’s time to loop through them, which is how real games display stats, menus, enemy info, and item details.
Let’s turn your dictionary into a readable, scrollable, game-ready info panel.
1. Looping Through KEYS
This loop gives you each key in the dictionary.
player = {
"name": "Aria",
"health": 100,
"level": 3
}
for key in player:
print(key)
This prints:namehealthlevel
Perfect for listing stat categories.
2. Looping Through VALUES
Sometimes you only want the data, not the labels.
player = {
"name": "Aria",
"health": 100,
"level": 3
}
for value in player.values():
print(value)
This prints:Aria1003
Great for quick displays or comparisons.
3. Looping Through BOTH (key + value)
This is the most useful loop — the one games use to show full stat screens.
player = {
"name": "Aria",
"health": 100,
"level": 3
}
for key, value in player.items():
print(key, ":", value)
This prints:name : Ariahealth : 100level : 3
Now your dictionary is basically a character sheet.
4. Why This Matters for Games
Looping through dictionaries lets you build:
- player stat menus
- enemy info screens
- item detail windows
- shop item descriptions
- settings menus
- quest logs
Any time you need to display structured data, this is your tool.
Mini-Challenge #1
Challenge:
Create a dictionary called enemy with:
- name
- health
- attack
Then loop through it and print each key and value.
Mini-Challenge #2
Challenge:
Create a dictionary called item with
- name
- type
- value
Then loop through just the values and print them.


