Deviopath › Python

Stock Lookup

Easy · Dictionaries

Reading a missing key with d[key] raises a KeyError. d.get(key, default) returns the default instead.

Write a function stock_of(inventory, item) that returns how many of item are in stock, where inventory is a dict like {"apple": 5}. Items that are not in the dict have a stock of 0.

Next: Merge Settings