Sales (2 points)

A company that sells supplies to steel companies has the following data:

  • a sales dictionary (dict) in which the key is the name of a client (str) and the value is a list of tuples (tuple). Each tuple corresponds to a sale and has three items: the month (int) and the day (int) in which the sale was made, and the sales amount in euros (float).

  • a month sales file with the sales made in a specific month. Each line of this file corresponds to a sale offer and has 3 or 4 data fields separated by a colon (':'): the day (int), the client name (str), and a Boolean (bool) showing whether this offer ended up in a sale (True) or not (False). If the Boolean is True, this line has a 4th data field which is the sold sale amount (float).

Write a modifier function sales() that takes a sales dictionary and the name of a month sales file (str) as those described, and a 3rd parameter which is the month number (int) that corresponds to the month sales file. This function modifies the given dictionary taking into account the contents of the given file, that is, adding to it the sales included in this file. Beware: you must only add to the dictionary those sale offers in the file that ended up in a sale. Once the dictionary has been updated, the lists of each item must be sorted chronologically, i.e., first by month and then by day.

Save this function in file sales.py.

Example:

For a data file with the name steel1.txt with the following content:

20:Gerdau:True:46.0
11:Acerinox:True:24.2
8:Metinvest:False
6:Acerinox:True:33.0

this function must pass the following tests:

>>> dsteel1 = {'Gerdau': [(2, 4, 39.5)],
...           'Metinvest': [(10, 6, 44.6), (1, 7, 65.8)],
...           'Sidetur': [(2, 2, 22.7)]}

>>> sales('steel1.txt', dsteel1, 9)
>>> if dsteel1 !={'Gerdau': [(2, 4, 39.5), (9, 20, 46.0)],
...               'Metinvest': [(1, 7, 65.8), (10, 6, 44.6)],
...               'Sidetur': [(2, 2, 22.7)],
...               'Acerinox': [(9, 6, 33.0), (9, 11, 24.2)]}:
...    print(dsteel1)

Note

Tests for automatic debugging are provided in file test-sales.txt.