A dict maps hashable keys to values with O(1) average lookup and preserves insertion order (3.7+). Access patterns Need Code Value or error d["key"] → KeyError if missing Value or default d.get("key", default) Insert if missing d.setdefault("key", []) Remove d.pop("key", None), del d["key"] Merge d1 d2 (3.9+), d1.update(d2), {d1, d2} Iterate for k, v in d.items(): collections helpers defaultdict(list) — auto-creates missing values. Counter — counting and mostcommon(). OrderedDict — movetoend, useful for LRU caches. ChainMap — layered lookups (CLI args → env → defaults). Nested data JSON maps naturally to dicts and lists: json.loads / json.dumps(indent=2).
Key Takeaways
Dicts keep insertion order and give O(1) lookups.
Use get() for defaults and setdefault()/defaultdict for grouping.
Merge with (3.9+) or {a, b}.
Counter, defaultdict and ChainMap cover most aggregation needs.