Amabon (2 points)

Amabon, an e-commerce company wants us to help with its costumers’ purchases. It has a nested list in which each sublist corresponds to a customer. The first item of each customer list is its name (str) and then there are some tuple corresponding to each individual product that this costumer has bought. Each tuple has two items: the product name (str) and the number of these products purchased by this costumer (int). There is also a dictionary of product prices (dict) with pairs of the form product_name : price. Prices are rounded to integers (int).

Save the following function to file amabon.py.

Write a modifier function amabon() that takes a list and a dictionary as those described, and modifies the list by adding at the end of each costumer the total amount spent in the bought products. Examples:

>>> lcost = [['Hanna', ('fork', 12)], ['Beth', ('knife', 4), ('glass', 3)],
... ['Peter', ('glass', 6), ('fork', 6), ('knife', 6), ('spoon', 6)]]
>>> dprices = {'glass': 3, 'fork': 5, 'knife': 8, 'spoon': 5}

>>> amabon(lcost, dprices)
>>> for cost in lcost:
...    cost
['Hanna', ('fork', 12), 60]
['Beth', ('knife', 4), ('glass', 3), 41]
['Peter', ('glass', 6), ('fork', 6), ('knife', 6), ('spoon', 6), 126]

Note

You have more tests in file test-amabon.txt