Junior Codes
The Treasure Archive

Counting Votes with a Python Dictionary for Kids

Tally how often each thing appears using a dictionary and a loop.

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.

Counting with dictionaries, explained simply

Imagine counting class votes for a trip: beach, zoo, beach, museum, beach. You make a tally mark next to each place as you read the votes. A dictionary can keep that tally for you.

Loop through the votes. For each one, if it is not yet in the dictionary, start it at 0. Then add 1. At the end each key holds how many times it appeared.

.get(key, 0) combines both steps: it gives the current count, or 0 if the key is new.

Example: Tally the votes

votes = ["beach", "zoo", "beach", "museum", "beach"]
tally = {}
for place in votes:
    tally[place] = tally.get(place, 0) + 1
print(tally)

Output

{'beach': 3, 'zoo': 1, 'museum': 1}

Try this

  • Count the letters in your name.
  • Find the winner by looping through the tally and remembering the biggest count.
  • Count the words in a sentence using .split() to break it into a list first.

Practise it in Wonderwild

“Count the festival votes”

Mission 22 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

What does tally.get(place, 0) mean?+

It looks up place in the tally. If it is there you get its count; if not, you get the 0 you supplied instead of an error.

Where is this pattern used in real programs?+

Counting page visits, finding the most common word in a book, scoring polls and building leaderboards all use the same idea.

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