CurriculumChoosing Python Data Structures, for KidsThe Dragon Census
Practice Challenge: Choosing Python Data Structures Under Pressure
Three questions about one list of dragons — choosing the right tool for each, without new tricks.
The Dragon Census
You know list-of-dicts, nested access, and sets. The challenge ahead just asks you to pick the right one for each question.
"How many total" is always len() on the list itself — no loop needed.
party = [{'name': 'Ember'}, {'name': 'Blaze'}]
print(len(party))Output
2"How many DIFFERENT X" means: collect that field from every item, then build a set and check its length.
types = ['fire', 'fire', 'ice']
print(len(set(types)))Output
2"Is there AT LEAST ONE that matches" is search-with-a-flag — the pattern from the algorithms topic, reused here exactly as it was taught.
Nothing new — just recognising which question is being asked, and reaching for the tool built for it.
Check your understanding
party has 5 dragons. Which tool answers 'how many dragons are there total'?
Why: len(party). For 'how many total' on a list, len() is always the direct answer — no loop needed at all. Loops earn their keep for questions len() can't answer on its own, like 'how many of a certain TYPE.'
You need to know how many DIFFERENT dragon types are in the party. What's the right sequence of tools?
Why: Collect the types into a list, then set() it and check the length. len(party) only ever answers 'how many dragons' — it has no idea some of them might share a type. A set is specifically the tool for 'how many DIFFERENT values,' which is a separate question from the total count.
What you'll practice
party = [{'name': 'Ember', 'type': 'fire'}, {'name': 'Blaze', 'type': 'fire'}]. Print how MANY dragons are in the party, using the tool built for 'how many total' — not a loop with a counter.
More from this topic
The Dragon Census 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 →