Junior Codes
The Treasure Archive

Python Dictionaries for Kids

Look things up by name using keys and values.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Dictionaries, explained simply

A real dictionary lets you look up a word to find its meaning. A Python dictionary works the same way: you look up a key to find its value.

You write a dictionary with curly brackets, putting a colon between each key and its value and commas between the pairs. To look something up, put the key in square brackets.

You can add a new pair or change an existing one by assigning to a key. If you ask for a key that is not there, Python raises a KeyError, so .get() is a safe way to look something up.

Example: A creature field guide

guide = {"owl": "night", "lark": "morning"}
print(guide["owl"])
guide["bat"] = "night"
print(len(guide))
print(guide.get("fox", "unknown"))

Output

night
3
unknown

Try this

  • Make a dictionary of three friends and their favourite colours.
  • Loop through a dictionary with for name in guide: and print each key and value.
  • Change the value for one key and print the dictionary again.

Practise it in Wonderwild

“The creature field guide”

Mission 21 in The Treasure Archive, one of 36 Python missions in Wonderwild.

Your child writes and runs real Python in the browser while Pip reacts to every line. Nothing to install. For ages 7+.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Questions parents and kids ask

When should I use a dictionary instead of a list?+

Use a list when order matters and you look things up by position. Use a dictionary when you want to look things up by a name, like a word, a username or a product.

Can two keys be the same?+

No. Each key appears only once. Assigning to an existing key replaces its value.

Prefer learning with a teacher?

Our live Python for Young Developers course teaches these ideas in small online classes led by a software engineer, with projects and feedback. Every live course also includes 12 months of full Wonderwild access for practice.

See the Python for Young Developers course