CurriculumChoosing Python Data Structures, for KidsThe same data, four shapes
Lists vs Dictionaries: Choosing the Right Python Data Structure
Two parallel lists, a list of dicts, a dict of lists — the same info, genuinely different tradeoffs.
The same data, four shapes
You know lists and dicts as separate tools. This topic is about CHOOSING between them — and combining them — for the same real data.
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.
names = ['Ember', 'Blaze']
hps = [40, 25]
print(names[0], hps[0])Output
Ember 40A list of dicts fixes that: each dragon is ONE dict, keeping its own name and hp bundled together, so they can never drift apart.
party = [{'name': 'Ember', 'hp': 40}, {'name': 'Blaze', 'hp': 25}]
print(party[0]['name'], party[0]['hp'])Output
Ember 40A dict of lists flips it again: one dict, where each KEY holds a whole list of values across every dragon.
party = {'name': ['Ember', 'Blaze'], 'hp': [40, 25]}
print(party['name'][0], party['hp'][0])Output
Ember 40All 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.
There's no single right shape — the right one depends on the question you'll be asking most.
Check your understanding
names = ['Ember', 'Blaze'] and hps = [40, 25], kept as TWO separate lists. What's the real risk of this shape?
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.
party = [{'name': 'Ember', 'hp': 40}, {'name': 'Blaze', 'hp': 25}]. Which question is this shape naturally BEST at?
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.
What you'll practice
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.
More from this topic
The same data, four shapes is one lesson inside Choosing Python Data Structures, for Kids — see the full lesson order and what the whole topic covers.
View the full topic →