Salespeople¶
Vendor sales data for a company is represented as a list where each element is a sublist that contains the information of a specific seller: its identifier (integer), working area (string) and sales figure (integer). A salesperson is assigned to a unique area and therefore a sales identifier will appear in the list at most once. For instance, the following list represents the data for 4 salespeople:
[[1182,'EMEA',1302], [1173,'AMS',1372], [1190,'EMEA',232], [1107,'AMS',173]]
Save the following functions into the file sales.py.
Write the function
below_threshold()that takes a list as described and a threshold sales figure, s, and returns the identifier corresponding to the first salesperson with a sales figure below s. If there is not such salesperson, the function must return the value -1.See the following examples:
>>> salespeople = [[1182,'EMEA',1302], [1173,'AMS',1372], [1190,'EMEA',232], [1107,'AMS',173]] >>> below_threshold(salespeople, 300) 1190 >>> below_threshold(salespeople, 100) -1
Note
More tests are provided in the file
sales1.txtWrite the function
delete_id()that takes a list as described and an identifier, and returns a new list without the sublist corresponding to the salesperson with the given identifier. If there is not such salesperson, the function must return a list equal to the given one.See the following examples:
>>> salespeople = [[1182,'EMEA',1302], [1173,'AMS',1372], [1190,'EMEA',232], [1107,'AMS',173]] >>> delete_id(salespeople, 1182) [[1173, 'AMS', 1372], [1190, 'EMEA', 232], [1107, 'AMS', 173]] >>> delete_id(salespeople, 1173) [[1182, 'EMEA', 1302], [1190, 'EMEA', 232], [1107, 'AMS', 173]] >>> delete_id(salespeople, 3000) [[1182, 'EMEA', 1302], [1173, 'AMS', 1372], [1190, 'EMEA', 232], [1107, 'AMS', 173]]
Note
More tests are provided in the file
sales2.txtWrite the function
drastic_policy()that takes a list as described and a threshold sales figure, s, and returns a new list without the sublist corresponding to the first salesperson with a sales figure below s. If there is no such salesperson, the function must return a list equal to the given one. This function must call the two previous ones.See the following examples:
>>> salespeople = [[1182,'EMEA',1302], [1173,'AMS',1372], [1190,'EMEA',232], [1107,'AMS',173]] >>> drastic_policy(salespeople, 300) [[1182, 'EMEA', 1302], [1173, 'AMS', 1372], [1107, 'AMS', 173]] >>> drastic_policy(salespeople, 100) [[1182, 'EMEA', 1302], [1173, 'AMS', 1372], [1190, 'EMEA', 232], [1107, 'AMS', 173]]
Note
More tests are provided in the file
sales3.txt
Solution
A solution of these functions is provided in the file sales.py.