Editor

Build a Word Counter

Intermediate · Write the code · from Python Dictionaries: The Complete Guide with Real Examples

From the lesson: Python Dictionaries: The Complete Guide with Real Examples

Open the contacts app on your phone. You look up a person by name and get their phone number. You don't search by position - you don't say "give me contact number 47." You search by name.

Read the lesson

Count how many times each word appears in the given list. Store the counts in a dictionary called word_counts, then print it.

Expected output:

{'hello': 3, 'world': 2, 'python': 1}
words = ['hello', 'world', 'hello', 'python', 'hello', 'world']
# Build a word count dictionary
# Print the result

More Dictionaries exercises

All Python exercises · 50 practice problems · Data Structures quiz