You’ll be able to
- Store key-value pairs with dict literals
{} - Look up, update, and delete entries safely
- Iterate over keys, values, and items with
.keys(),.values(),.items() - Use
.get()to avoidKeyErrorwhen accessing missing keys
Loading lesson…
Why this matters
Dicts back every JSON API response, Django ORM row, and pandas record. Redis, MongoDB, and even Python's own class attributes are dicts under the hood. Fluency here is non-negotiable for backend or data roles.
Common pitfalls
- Accessing a missing key with
d[k]raisesKeyError. Used.get(k)ord.get(k, default)for safe lookups. - Using mutable objects like lists as keys. Only hashable types (
str,int,tuple) work; lists raiseTypeError. - Iterating
for k in dand expecting values. That yields keys; used.items()for pairs.