A final balance can hide a shortage earlier in the day.
balance = 3
changes = [-4, 5]
for delta in changes:
balance += delta
print(balance)
# -1
# 4Check each intermediate balance before applying the next change. In the shop each product has its own balance.
Implement first_shortage(stock, changes). Opening counts are nonnegative. Process the (item, integer delta) pairs in order and return the name of the first item whose balance drops below zero. Missing items start at zero. Return None if every balance stays nonnegative. Preserve the opening dictionary.
first_shortage({"tea": 2}, [("tea", -2), ("milk", -1), ("milk", 5)]) # "milk"