A shop keeps its stock in inventory, a map from item names to how many of each item it has. A delivery brings amount more of item. Add amount to the count of item and return the updated dictionary.
Only the count of item changes: every other entry stays as it is. The order of the entries doesn't matter.
Example 1:
Input: inventory = {"apples": 5, "bananas": 2, "cherries": 10}, item = "bananas", amount = 3
Output: {"apples": 5, "bananas": 5, "cherries": 10}
Explanation: "bananas" had a count of 2, and 2 + 3 = 5. The apples and the cherries keep their counts.
Example 2:
Input: inventory = {"milk": 0}, item = "milk", amount = 12
Output: {"milk": 12}
Explanation: A count of 0 means the milk was sold out. The delivery brings it to 0 + 12 = 12.
Example 3:
Input: inventory = {"pens": 7, "paper": 3}, item = "pens", amount = 1
Output: {"pens": 8, "paper": 3}
Explanation: One more pen: 7 + 1 = 8.
Constraints:
itemis always a key ofinventory.amountis at least 1.- Every count is 0 or more.
- Item names are single lowercase words, and they are all different.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
