Python Dictionary Practice With Five Beginner Exercises
Last term, eleven of the fourteen beginners in our Thursday group could write a working loop by week three. Only four could explain what a dictionary was by week six.

Last term, eleven of the fourteen beginners in our Thursday group could write a working loop by week three. Only four could explain what a dictionary was by week six. That gap is common, and it matters, because once you start building anything real in Python, from a quiz game to a club attendance tracker, dictionaries do most of the heavy lifting. Good Python dictionary practice closes that gap faster than reading about them ever will.
This guide gives you a plain mental model, then five exercises that build on each other, the same ones I hand out in club sessions. Each takes 10 to 25 minutes. Type them out yourself instead of copying, and run each one before moving on.
A Mental Model Before Python Dictionary Practice
A list is a row of numbered boxes. You find things by position: the first item, the third item. A dictionary is a set of labelled drawers. You find things by name.
In code, a dictionary looks like this: scores = {"amara": 12, "leo": 9, "priya": 15}. The names on the left of each colon are keys. The numbers on the right are values. To get Leo's score, you write scores["leo"] and Python hands you 9.
Three rules cover most early confusion:
- Keys must be unique. Writing scores["leo"] = 11 replaces the old value instead of adding a second Leo.
- Keys are usually strings or numbers. Lists cannot be keys.
- Asking for a key that does not exist raises a KeyError, which is the most common dictionary error beginners see.
Exercise One: Build a Pet Age Lookup
Create a dictionary with three pets and their ages. Then print one pet's age, change another pet's age, and add a fourth pet.
- Start with pets = {"biscuit": 4, "mango": 2, "pepper": 7}.
- Print pets["mango"].
- Set pets["biscuit"] = 5 because Biscuit had a birthday.
- Add pets["noodle"] = 1.
- Print the whole dictionary and check that four pets appear.
If you see a KeyError, check spelling and capital letters. Python treats "Mango" and "mango" as different keys, and this catches nearly every learner once.
Exercise Two: Loop Through Keys and Values
Dictionaries become useful when you combine them with loops. If loops still feel shaky, spend ten minutes with this explanation of Python loops using everyday tasks first.
Using your pets dictionary, write a loop that prints a sentence for every pet, such as "pepper is 7 years old". The tool you want is pets.items(), which gives you each key and value together: for name, age in pets.items():
Then extend it. Print only pets older than 3. Then count how many pets are older than 3 and print that number at the end. The second step forces you to combine a loop, an if statement and a counter, which is exactly the pattern you will reuse constantly.
Exercise Three: Count Words in a Sentence
This is the classic exercise, and for good reason. Take the sentence "the cat sat on the mat with the hat" and count how often each word appears.
The step by step approach
- Split the sentence into a list of words with sentence.split().
- Create an empty dictionary called counts.
- Loop over the words. If a word is already a key, add 1 to its value. If not, set its value to 1.
- Print counts. You should see "the" with a value of 4.
Once that works, try a shorter version using counts.get(word, 0) + 1. The get method returns a default value instead of crashing when the key is missing. Write the long version first, though. Seeing why the if check is needed teaches you more than the shortcut does.
Why Memorising Dictionary Methods Is a Waste of Early Practice
Many tutorials open with a list of a dozen dictionary methods: keys, values, items, get, pop, update, setdefault and more. Beginners dutifully try to memorise them and forget most within a week.
I push back on that approach in club sessions. You need four things in your first month: square bracket lookup, assignment, items() for looping and get() for safe lookup. Everything else you can search for when a project needs it. Memorising methods you have no use for yet feels productive, but it is reading, not practice. Spend that time on the exercises instead, and the methods you actually use will stick on their own.
Exercise Four: A Tiny Quiz Game
Now build something you can show a friend. Store questions as keys and answers as values:
quiz = {"capital of France": "paris", "largest planet": "jupiter", "number of legs on a spider": "8"}
Loop through the quiz, ask each question with input(), compare the answer after converting it to lowercase, and keep a score. At the end, print something like "You got 2 out of 3".
Common bugs at this stage include comparing "8" with 8, forgetting .lower() on the player's answer, and resetting the score inside the loop instead of before it. If one of these trips you up, this list of common Python mistakes covers the fixes.
Exercise Five: Nested Dictionaries for a Club Roster
Real data often has more than one value per person. A dictionary can hold another dictionary:
roster = {"amara": {"age": 13, "language": "python", "projects": 3}, "leo": {"age": 14, "language": "scratch", "projects": 1}}
Your tasks:
- Print Amara's language using roster["amara"]["language"].
- Add a third member with all three fields.
- Loop through the roster and print the name of everyone who has finished more than one project.
- Calculate the total number of projects across the whole club.
When this works, you have used every dictionary skill a beginner needs for small projects. Many of our club members turn this exercise into an attendance tracker or a leaderboard for their next session.
FAQ
When should I use a dictionary instead of a list?
Use a dictionary when you look things up by a name or label, such as a username or a product code. Use a list when order matters and you mostly go through every item in sequence.
Are Python dictionaries ordered?
Yes. Since Python 3.7, dictionaries keep the order in which keys were added. Older tutorials may say otherwise, so check the date on anything you read.
How long should I practise before moving on?
Finish all five exercises, then rebuild exercise three from memory a day later. If you can do it in under ten minutes without looking anything up, you are ready for small projects.
Do One Exercise Tonight
Pick exercise one, set a 15 minute timer and type it out from scratch. Tomorrow, do exercise two. Five short sessions spread over a week will teach you dictionaries more thoroughly than one long evening. When you finish, find more drills in the Python practice section.
More in Python and Practice
Python and Practice
How to Practice Python With Small Daily Exercises
People learn to code the way they learn an instrument, through regular small practice rather than occasional marathon sessions.
Python and Practice
Common Python Mistakes New Coders Repeat and How to Fix Them
I have watched a lot of beginners work through their first few weeks of Python, and the mistakes rarely surprise me anymore.
Python and Practice
Why Your First Functions Should Do Only One Thing
A beginner's first few functions almost always try to do genuinely too much at once, calculate a value, print a result, and...