The dragon explains
The Dragon Census
The dragon: You know list-of-dicts, nested access, and sets. The challenge ahead just asks you to pick the right one for each question.
The dragon: "How many total" is always len() on the list itself — no loop needed.
example.pyPython 3party = [{'name': 'Ember'}, {'name': 'Blaze'}]print(len(party))
Output2The dragon: "How many DIFFERENT X" means: collect that field from every item, then build a set and check its length.
example.pyPython 3types = ['fire', 'fire', 'ice']print(len(set(types)))
Output2The dragon: "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.
The dragon: Nothing new — just recognising which question is being asked, and reaching for the tool built for it.
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
party has 5 dragons. Which tool answers 'how many dragons are there total'?
- len(party) — a direct call, no loop neededCorrect
- A loop with a counter, adding 1 for every dragon
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.'
Question 2 of 2
You need to know how many DIFFERENT dragon types are in the party. What's the right sequence of tools?
- Collect each dragon's type into a list, then build a set from that list and check its lengthCorrect
- Just call len(party) — the total count and the type count are the same thing
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.
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
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.
- +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.