The dragon explains
The same data, four shapes
The dragon: You know lists and dicts as separate tools. This topic is about CHOOSING between them — and combining them — for the same real data.
The dragon: Two parallel lists: names and hps, kept in matching order. It works, but it's fragile — nothing stops the lists from drifting out of sync.
example.pyPython 3names = ['Ember', 'Blaze']hps = [40, 25]print(names[0], hps[0])
OutputEmber 40The dragon: A list of dicts fixes that: each dragon is ONE dict, keeping its own name and hp bundled together, so they can never drift apart.
example.pyPython 3party = [{'name': 'Ember', 'hp': 40}, {'name': 'Blaze', 'hp': 25}]print(party[0]['name'], party[0]['hp'])
OutputEmber 40The dragon: A dict of lists flips it again: one dict, where each KEY holds a whole list of values across every dragon.
example.pyPython 3party = {'name': ['Ember', 'Blaze'], 'hp': [40, 25]}print(party['name'][0], party['hp'][0])
OutputEmber 40The dragon: All three answer 'what's Ember's hp' correctly. The difference is what's EASY to do next — a list of dicts makes 'loop over every dragon' natural; a dict of lists makes 'get every hp at once' natural.
The dragon: There's no single right shape — the right one depends on the question you'll be asking most.
Quick check
Check your understanding
Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.
Question 1 of 2
names = ['Ember', 'Blaze'] and hps = [40, 25], kept as TWO separate lists. What's the real risk of this shape?
- The two lists can drift out of sync — nothing enforces that position 0 in both always describes the same dragonCorrect
- Python won't allow two separate lists describing related data
Why: The lists can drift apart. If someone adds a new dragon to names but forgets hps, position 0 in each list no longer describes the same dragon — Python has no way to catch that, because nothing about the two lists actually connects them except the programmer's care.
Question 2 of 2
party = [{'name': 'Ember', 'hp': 40}, {'name': 'Blaze', 'hp': 25}]. Which question is this shape naturally BEST at?
- Looping over every dragon and doing something with each one's full set of statsCorrect
- Getting every dragon's hp at once, as a single list
Why: Looping over each dragon. A list of dicts keeps everything about ONE dragon bundled together, which is exactly what you want when processing dragons one at a time — 'for dragon in party: do something with dragon' reads naturally. Getting just the hps across everyone is actually easier in the OTHER shape.
In the game
What you'll practice
Three levels in the game: one guided first try with the shape of the answer already there, then two to solve on your own.
- 1
GuidedYour first try
names = ['Ember', 'Blaze'] and hps = [40, 25] — two SEPARATE lists, kept in matching order. Print Ember's name and HP together, using position 0 in both lists.
- +2
PracticeTwo more, on your own
This lesson is part of PRO.
PRO is a one-time $49.99 purchase, no subscription, and unlocks this whole topic along with everything else. Topics 1–3 are free, start to finish.
Unlock this lesson with PROStuck three times? The game offers the answer — unasked.