Dictionaries and Sets
Dictionaries & Sets — cheat sheet
Fast key-value mapping and mathematical set operations in Python.
Dictionary basics
d = {"name": "Alice", "age": 25}Define key-value pairs.
d["email"] = "a@b.com"Insert new or update existing key.
val = d.get("role", "guest")Safe lookup with default fallback.
Set operations
s = {1, 2, 3}Set of unique items.
union = s1 | s2Combine items from both sets.
common = s1 & s2Intersection: items present in both.