Parent guide · 5 min read
Python dictionaries for kids: looking a value up by its name
A list keeps many things in order and finds them by position number. Often a name is a better way to find something: a phone book looks a number up by a person’s name, and a game looks up a score by a player’s name. Python’s dictionary does exactly that. This guide explains the idea, traces an example line by line, and lists the errors beginners meet.

Try this tonight
5 things you can do at home
Make a dictionary on paper first
Write three names down the left and a score beside each. The names are the keys and the scores are the values. Ask "what is Mia’s score?" Doing it by hand first shows that you look up by name, not by position.
Type the smallest dictionary and print it
Run scores = {"Mia": 8, "Leo": 5} and then print(scores), print(scores["Mia"]) and print(len(scores)). Predict each output before pressing run.
Add and change an entry
Try scores["Zoe"] = 9 and print the dictionary again, then scores["Leo"] = 6. The same line adds a new key if it is not there and changes the value if it is, which surprises many beginners.
Walk through every pair with a loop
Try for name in scores: print(name, scores[name]). It visits each key in turn. Do this once loops feel comfortable on their own.
Make the error on purpose
Print scores["Ben"], which is not in the dictionary, and read the message together: KeyError: 'Ben'. Seeing the error once, with the cause known, takes the fear out of the next time.
Keys and values
A dictionary is a set of labelled boxes. The label is the key and the contents are the value. In {"Mia": 8, "Leo": 5} the keys are "Mia" and "Leo" and the values are 8 and 5. Each key appears once, so adding a key that already exists replaces its value rather than creating a second one.
Keys are usually text or numbers, written with quotes if text. Values can be anything, including a list. Unlike a list, you do not count positions at all: you ask for the thing by its name.
When to pick a dictionary and when a list
Use a list when the order or the position matters, such as the scores of a game in the order they were played. Use a dictionary when you want to find something by a name you choose, such as one score for each player.
A quick test: if you would want to ask "what is the value for ___?" with a word or name in the blank, it is a dictionary. If you would ask "what is item number ___?", it is a list.
Worked example: tracing a dictionary, line by line
Take scores = {"Mia": 8, "Leo": 5}. Then scores["Mia"] is 8 and len(scores) is 2. After scores["Zoe"] = 9 the dictionary has three pairs: Mia 8, Leo 5, Zoe 9. After scores["Leo"] = 6, Leo’s value is 6 and the length is still 3, because Leo was changed, not added.
Now a safe lookup: scores.get("Ben") gives None instead of an error when the key is missing, and scores.get("Ben", 0) gives 0. Tracing every line by hand, and only then running the code to compare, is the best check that a child understands rather than copies.
The errors beginners hit most
KeyError comes from asking for a key that is not in the dictionary. Check the spelling and the capital letters, since "mia" and "Mia" are different keys. Forgetting the quotes round a text key gives a NameError, because Python thinks Mia is a variable.
Another is using square brackets to make the dictionary, which makes a list, or writing a colon as a comma. Curly brackets with key: value pairs is the shape to remember. Reading the error message aloud, line by line, solves most of these.
Signs it’s time for outside help
When home help has done what it can
- Keeps getting KeyError and cannot say why.
- Tries scores[0] on a dictionary, as if it were a list.
- Makes a separate variable for every name instead of one dictionary.
- Confuses curly brackets, square brackets and round brackets.
- Copies dictionary code that works but cannot predict its output before running it.
Questions parents ask
FAQ
What is a dictionary in Python?
A dictionary stores pairs of a key and a value in curly brackets, for example {"Mia": 8, "Leo": 5}. You look a value up by its key, and entries can be added, changed and removed after it is made.
What is the difference between a list and a dictionary?
A list finds items by position number, starting at 0. A dictionary finds values by a key you choose, such as a name. Use a list when order matters and a dictionary when names matter.
How do I add something to a dictionary?
Assign to a new key, for example scores["Zoe"] = 9. If the key already exists, the same line changes its value instead.
Does my child need lists before dictionaries?
It helps. Lists introduce brackets, indexes and loops over a collection, and a dictionary then builds on the idea by swapping the position for a name.
Further reading
Classes that fit
Live, 50–55 minutes, four learners at most or 1-on-1.
Not sure which is right for your child?
Tell us their age and what they have tried so far, and we will suggest where to start before you book anything.

