Suppose Company Maintains Multiple Warehouses Warehouse Stocks Various Products Warehouses Q43885522
Suppose that a company maintains multiple warehouses. Eachwarehouse stocks various products (not all warehouses stock thesame products). The inventory of a product is the amount of anyproduct available at a warehouse. For example, a warehouse inIrvine may stock a brush product, and it may have an inventory of 3(3 brushes in the Irvine warehouse).
We will represent all this information in a dictionary whosekeys are the warehouses: associated with each warehouse is an innerdictionary whose keys are the stocked products (and whoseassociated values are the inventory of that product in thewarehouse). The inventory must always be a non-negative value; aninventory of 0 is legal. For example, a simple/small database mightbe.
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 2wallets.
-
The Newport warehouse stocks 7 combs, and 0 staplers.
-
The Tustin warehouse stocks 3 keychains, 4 pencils, and 3wallets.
I have printed this dictionary in an easy to read form. Pythonprints dictionaries on one line, and can print their key/values inany order, because dictionaries are not ordered. In the followingfunction, do not mutate this dictionary; you can create local datastructures in the functions and mutate them as necessary.
(a) The product_locations function returns a list of 2-tuples:the first index in the 2-tuple is a product name; the second indexis another list of 2-tuples: (warehouse, inventory). In theoutermost list, the products appear in increasing alphabeticalorder; in each inner list (for each product) the warehouses appearin increasing alphabetical order: for the db dictionary above theresult is
[(‘brush’, [(‘Irvine’, 3)]),
(‘comb’, [(‘Irvine’, 2), (‘Newport’, 7)]), (‘keychain’, [(‘Tustin’,3)]),
(‘pencil’, [(‘Tustin’, 4)]),
(‘stapler’, [(‘Newport’, 0)]),
(‘wallet’, [(‘Irvine’, 2), (‘Tustin’, 3)]) ]
Expert Answer
Answer to Suppose that a company maintains multiple warehouses. Each warehouse stocks various products (not all warehouses stock t…
OR