Question: in a dictionary whose keys are the warehouses: associated with each warehouse is an inner dictionary whose keys are the stocked products (and whose associated
in a dictionary whose keys are the warehouses: associated with each warehouse is an inner dictionary whose keys are the stocked products (and whose associated values are the inventory of that product in the warehouse). The inventory must always be a non-negative value; an inventory of 0 is legal. For example, a simple/small database might be.
db = {'Irvine' : {'brush': 3, 'comb': 2, 'wallet': 2}, 'Newport': {'comb': 7, 'stapler': 0}, 'Tustin' : {'keychain': 3, 'pencil': 4, 'wallet': 3}}
This data structure means that
-
The Irvine warehouse stocks 3 brushes, 2 combs, and 2 wallets.
-
The Newport warehouse stocks 7 combs, and 0 staplers.
-
The Tustin warehouse stocks 3 keychains, 4 pencils, and 3 wallets.
(d) The by_product_inventory function returns a list of 2-tuples (str,int) (product names and inventory), sorted ascending by which products have the largest inventory (the summed over all warehouses). If two products have the same inventory, they should appear in ascending order of product name: for the db dictionary above the result is [('stapler', 0), ('brush', 3), ('keychain', 3), ('pencil', 4), ('wallet', 5), ('comb', 9)].
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
