Dictionary lookup and iteration
Learn in depth →A dictionary maps hashable keys to values and preserves insertion order.
mapping[key]; mapping.get(key, default); mapping.items()Example
counts = {"tea": 2}
print(counts.get("coffee", 0))
for name, count in counts.items():
print(name, count)Result
0 tea 2
Watch for: [] raises KeyError for a missing key. get does not insert its default. setdefault may insert it.
Practise this topic →