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 5
  • PRO
  • Ages 10+
  • 3 hands-on levels
See what PRO unlocksA one-time $49.99 purchase. Topics 1–3 are free.

The dragon explains

A dict is a stat sheet

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

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

    example.pyPython 3
    dragon = {"name": "Ember", "hp": 40}
  3. The dragon: dragon["hp"] gets the value stored under the "hp" key. Not "the second thing" — the thing NAMED hp.

    example.pyPython 3
    print(dragon["hp"])
    Output40
  4. The dragon: 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.

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

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

    question.pyPython 3
    dragon = {"name": "Ember", "hp": 40}print(dragon["name"])
    • EmberCorrect
    • "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.

  2. Question 2 of 2

    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 dictCorrect
    • 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.

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

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

  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.