§ 2.4.2section 8 of 18·~4 min
Dictionaries
A dict stores key → value pairs. Think of it as one row where the keys are column names. A list of dicts is a whole table, and it's exactly what most APIs send back.
order = {"id": 1042, "amount": 499, "city": "Pune"}
print(order["city"])
order["status"] = "paid" # add a new key
print(order.get("coupon")) # missing key, no crash
for key, value in order.items():
print(key, value)
OUTPUT
Pune
None
id 1042
amount 499
city Pune
status paidReading values safely
order["coupon"] crashes with a KeyError when the key doesn't exist. order.get("coupon") returns None instead, and order.get("coupon", 0) lets you choose the fallback.
on the job API payloads often leave out fields. Reading them with .get() and a sensible default stops one incomplete record from failing the whole load.