Menu

Dictionary Whose Keys Warehouses Associated Warehouse Inner Dictionary Whose Keys Stocked Q43885283

in a dictionary whose keys are the warehouses: associated witheach warehouse is an inner dictionary whose keys are the stockedproducts (and whose associated values are the inventory of thatproduct in the warehouse). The inventory must always be anon-negative value; an inventory of 0 is legal. For example, asimple/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

  1. The Irvine warehouse stocks 3 brushes, 2 combs, and 2wallets.

  2. The Newport warehouse stocks 7 combs, and 0 staplers.

  3. The Tustin warehouse stocks 3 keychains, 4 pencils, and 3wallets.

(d) The by_product_inventory function returns a list of 2-tuples(str,int) (product names and inventory), sorted ascending by whichproducts have the largest inventory (the summed over allwarehouses). If two products have the same inventory, they shouldappear in ascending order of product name: for the db dictionaryabove the result is [(‘stapler’, 0), (‘brush’, 3), (‘keychain’, 3),(‘pencil’, 4), (‘wallet’, 5), (‘comb’, 9)].

Expert Answer


Answer to in a dictionary whose keys are the warehouses: associated with each warehouse is an inner dictionary whose keys are the …

OR