CurriculumPython Dictionaries for KidsA dict is a stat sheet

Python Dictionaries Explained: Lookup by Key, Not Position

Named values, looked up by NAME instead of position — the key difference from a list.

Lesson 1 of 5PROAges 10+
See what PRO unlocks →

A dict is a stat sheet

You know lists — a row of things, looked up by POSITION. A dict is different: it looks things up by NAME.

dragon = {"name": "Ember", "hp": 40} — a dict, with two keys: "name" and "hp". Each key holds one value.

dragon = {"name": "Ember", "hp": 40}

dragon["hp"] gets the value stored under the "hp" key. Not "the second thing" — the thing NAMED hp.

print(dragon["hp"])

Output

40

That's the whole idea: a dict is a stat sheet where every value has a name, so you never have to remember which position it's in.

Check your understanding

dragon = {"name": "Ember", "hp": 40}. What does dragon["name"] give you?

dragon = {"name": "Ember", "hp": 40}
print(dragon["name"])
  • Ember
  • "name" — the key itself
  • 40 — the first value in the dict

Why: Ember. dragon["name"] looks up the value stored under the "name" key — by NAME, which is the whole point of a dict.

party = ["Ember", "Blaze"] is a LIST. dragon = {"name": "Ember"} is a DICT. How do you get the first item from each?

  • party[0] for the list, dragon["name"] for the dict
  • party[0] and dragon[0] — both use position

Why: party[0] for the list (position-based), dragon["name"] for the dict (name-based) — two different lookup systems for two different tools.

What you'll practice

dragon = {"name": "Ember", "hp": 40}. Print dragon["hp"] — the value stored under the "hp" key, looked up by name, not by position.

Unlock this lesson with PRO →

More from this topic

A dict is a stat sheet is one lesson inside Python Dictionaries for Kids — see the full lesson order and what the whole topic covers.

View the full topic →