Question: IN PYTHON 3 LANGUAGE write a function named update_purchases that takes a dict argument in the form illustrated on the top of page 2, each

IN PYTHON 3 LANGUAGE write a function named update_purchases that takes a dict argument in the form illustrated on the top of page 2, each key in the dict is a str (the warehouse) whose associated value is another dict: this inner dict associates a str (the product) with an int (the inventory) and a second argument that is a list of 2-tuples: two strs (warehouse, product). Each represents the sale of the specified product at the specified warehouse. It mutates the dict argument, decreasing by 1 the inventory of the specified product at the specified warehouse, each time one product is sold: these sales occur in the order shown in the list. It returns a set of 2-tuples for purchases that cannot be made because either 1. The warehouse is not legal (not in the dict) 2. The warehouse does not have that product available for sale: either it does not appear in the dict; or it appears, but has no inventory: none of that product is in stock. Such illegal purchases do not update the dictionary argument. Calling this function with the db dictionary shown below: update_purchases( db, [('Irvine', 'brush'), ('Newport', 'comb'), ('Tustin', 'car'), ('Newport', 'comb')] ) mutates db, decreasing the inventory of products successfully purchased (a brush from Irvine and a comb from Newport), which becomes DESIRED OUTPUT: {'Irvine': {'brush': 2, 'comb': 2, 'wallet': 2}, 'Newport': {'comb': 0, 'stapler': 0}, 'Tustin' : {'keychain': 3, 'pencil': 4, 'wallet': 3}}

Information needed: For example, the db1.txt file contains the lines brush:Irvine:3 comb:Irvine:2:Newport:1 wallet:Irvine:2:Tustin:3 stapler:Newport:0 keychain:Tustin:3 pencil:Tustin:4

db: {'Irvine': {'brush': 3, 'comb': 2, 'wallet': 2}, 'Newport': {'comb': 1, 'stapler': 0}, 'Tustin' : {'keychain': 3, 'pencil': 4, 'wallet': 3}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!