An Observable Dictionary

easy
Checkpoint challenge
Solve this to show you know the material and jump straight to Unit 11. Everything before it counts as cleared.

Implement ObservableDict, a dict that calls listeners whenever it changes. subscribe(fn) registers a callback called as fn(event, key, old, new) where event is "set", "update" (key existed with a different value) or "delete". Setting a key to its current value fires nothing.

Changes made through d[k] = v, del d[k], d.pop(k) and d.update(...) must all notify. subscribe returns a function that unsubscribes.

#dictionaries#callbacks#subclassing2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
An Observable Dictionary · TechGradify