Dictionaries
LockedLesson 9 of 60 · DataStructures · Medium
Mastery0% of 85%
Up next: Variables and Types (~7 min) →Finish these first:Lists →Or pass the tests below to unlock it now.
1
The big idea
Dicts map hashable keys to values with average O(1) lookup, preserving insertion order.
Think of it like this: Think of data structures as specialized toolboxes: a List keeps items in numbered slots (`0, 1, 2...`), a Set keeps only unique badges, and a Dictionary/Map labels each compartment with a custom name key.
Key words (tap to learn):
2
Read the lesson
Dicts map hashable keys to values with average O(1) lookup, preserving insertion order.
ages = {"ada": 36}
ages["bob"] = 41
ages.get("eve", 0)
for k, v in ages.items(): ...
from collections import Counter, defaultdict
3
Quick check
Before writing code: What should `count_chars('aab')` return when your implementation of Dictionaries is working?
4
2 sample tests, 1 hiddenYour challenge
Write count_chars(s) returning a dict of character counts.
Stuck? Get a hint (free)
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to java.maps-hashmap (90% overlap). `dict` ~ `HashMap<K,V>`; `get(k, d)` ~ `getOrDefault`.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Dictionaries.
Mastery0%
Learn this first
- ListsNot yet
Opens up next
This is the last lesson in this branch.