runtime
113 / 500
question 113 Collection Algorithms · easy

Lines from cancelled invoices

In the Online Retail II data, an invoice number that starts with C is a cancellation. The returns team wants the stock codes on cancelled invoices so they can restock them.

Functioncancelled_codes(lines)
linesa list of invoice lines: dictionaries with "Invoice", "StockCode" and "Quantity"
Returnsthe StockCode of every line whose Invoice starts with "C", in the order the lines appear
Rulesonly the invoice number decides; a stock code that starts with C (such as the carriage charge C2) does not make a line cancelled
Examples
callcancelled_codes([{'Invoice': '489438', 'StockCode': '21329', 'Quantity': 28}, {'Invoice': 'C489528', 'StockCode': '85048', 'Quantity': -1}, {'Invoice': '489438', 'StockCode': '21252', 'Quantity': 30}, {'Invoice': 'C489541', 'StockCode': '21254', 'Quantity': -4}])returns['85048', '21254']
callcancelled_codes([{'Invoice': '489439', 'StockCode': '22139', 'Quantity': 6}])returns[]
callcancelled_codes([{'Invoice': 'C489555', 'StockCode': '21260', 'Quantity': -6}])returns['21260']

Loading your progress…

Lines from cancelled invoices — Python practice · Runtime