Looking up a missing dictionary key with brackets raises an error. The get method accepts a fallback as its second argument.
A departures board shows a gate even when a flight has not been assigned one.
gates = {"SK10": "C4"}
print(gates.get("SK10", "Pending")) # C4
print(gates.get("SK88", "Pending")) # Pending
print("SK88" in gates) # FalseThe fallback supplies a value for the display while the stored gates stay the same. A quantity lookup needs a numeric fallback.
Complete stock_for(stock, item) to return the saved quantity, or 0 for an unknown item. Do not insert missing items into stock.
stock_for({"pens": 4}, "pens") # 4
stock_for({"pens": 4}, "clips") # 0