question 114 Collection Algorithms · easy
Duplicate stock codes in a catalogue
Every product in a catalogue should have its own stock code. Before importing a catalogue, report the codes that break that rule.
Function
repeated_codes(products)productsa list of dictionaries with
"stock_code" and "description"Returnseach stock code that appears more than once, reported once, in the order the repeats are found (the moment its second copy is reached)
Rulescodes are compared exactly:
84031a and 84031A are different codes; no repeats gives []Examples
callrepeated_codes([{'stock_code': '21329', 'description': 'ITEM 21329'}, {'stock_code': '84031A', 'description': 'ITEM 84031A'}, {'stock_code': '21329', 'description': 'ITEM 21329'}, {'stock_code': '22139', 'description': 'ITEM 22139'}, {'stock_code': '84031A', 'description': 'ITEM 84031A'}])returns['21329', '84031A']
callrepeated_codes([{'stock_code': '21329', 'description': 'ITEM 21329'}, {'stock_code': '84031A', 'description': 'ITEM 84031A'}])returns[]
callrepeated_codes([{'stock_code': '85048', 'description': 'ITEM 85048'}, {'stock_code': '85048', 'description': 'ITEM 85048'}])returns['85048']