runtime
129 / 500
question 129 Comprehensions · hard

Stock count discrepancies

After a warehouse stock-take, compare what the system expected with what was counted on the shelves. Report every SKU whose counts differ, with the difference counted - expected. A SKU missing from one side counts as 0 there: a SKU found on the shelf that the system never heard of is a positive difference, and one the system expected but nobody found is negative.

Functionstock_differences(expected, counted)
expected, counteddictionaries from SKU to a whole number of units
Returnsa dictionary {sku: counted - expected} for every SKU, on either side, whose two numbers differ; {} when everything matches
Must notchange either dictionary
Examples
callstock_differences({'SPO-11681': 14, 'HOM-22847': 9, 'ELE-24781': 6}, {'SPO-11681': 14, 'HOM-22847': 7, 'TOY-54564': 2})returns{'HOM-22847': -2, 'ELE-24781': -6, 'TOY-54564': 2}
callstock_differences({'A': 1}, {'A': 1})returns{}
callstock_differences({}, {})returns{}

Loading your progress…

Stock count discrepancies — Python practice · Runtime