Practice Challenge: Choosing Python Data Structures Under Pressure

Three questions about one list of dragons — choosing the right tool for each, without new tricks.

  • Lesson 4 of 4
  • PRO
  • Ages 10+
  • 3 hands-on levels
See what PRO unlocksA one-time $49.99 purchase. Topics 1–3 are free.

The dragon explains

The Dragon Census

  1. 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.

  2. The dragon: "How many total" is always len() on the list itself — no loop needed.

    example.pyPython 3
    party = [{'name': 'Ember'}, {'name': 'Blaze'}]print(len(party))
    Output2
  3. The dragon: "How many DIFFERENT X" means: collect that field from every item, then build a set and check its length.

    example.pyPython 3
    types = ['fire', 'fire', 'ice']print(len(set(types)))
    Output2
  4. The 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.

  5. 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.

  1. 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.'

  2. 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. 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. +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 PRO

Stuck three times? The game offers the answer — unasked.