
Python practice
Python dictionary practice questions
16 problems, ordered from easiest. They run in your browser, and 7 are free.
Start with First Occurrence MapThe idea in a minute
A dictionary stores values under keys, so you can look something up by name instead of by position. It is the tool for counting, grouping and quick lookups.
Most problems here follow one pattern: walk through the data once, and update a dictionary as you go.
Example: Group names by city
people = [("Asha", "Pune"), ("Ravi", "Delhi"), ("Meera", "Pune")]
by_city = {}
for name, city in people:
by_city.setdefault(city, []).append(name)
print(by_city)What it prints
{'Pune': ['Asha', 'Meera'], 'Delhi': ['Ravi']}What to watch for
- Use get(key, default) so a missing key does not raise an error.
- Keys must be unchangeable, so a list cannot be a key but a tuple can.
- Looping over a dictionary gives its keys. Use .items() for keys and values.
Dictionaries problems
- First Occurrence Mapbeginner · Free
- Word Frequency Counterbeginner · Free
- Tasks that are ready to runbeginner · Free
- Quality gate for a batchbeginner · Free
- Count events per minutebeginner · Free
- Shared tags between two campaignsbeginner · Free
- Counter for warehouse zone visitsbeginner · Free
- Daily per-user event countsintermediate · Locked
- Latest valid location per driverintermediate · Locked
- Group-by on CSV text without pandasintermediate · Locked
- Hash join two lists of dictsintermediate · Locked
- Word frequency ignoring stop wordsintermediate · Locked
- Group orders by customer and statusintermediate · Locked
- Merge two JSON-like config dicts with overridesintermediate · Locked
- Validate a nested order schemaintermediate · Locked
- Diff 2 versions of a product catalogadvanced · Locked
Want a guided order across every topic? Open the practice sheets or the Python hub.