question 137 Built-ins & Sorting · medium
Restock lines without indexes
restock_lines works, but it indexes three parallel lists with range(len(...)), and a reviewer asked for zip. Refactor it to walk the three lists together with zip. Behaviour must not change: one (sku, units_to_order) tuple for each SKU whose stock on hand is below its minimum, in list order.
Function
restock_lines(skus, on_hand, minimum) (same name, same result)skus, on_hand, minimumthree lists of the same length, matched by position
Returnsa list of tuples
(sku, minimum - on_hand) for SKUs below their minimumStructurethe lists are walked with
zip, not by indexExamples
callrestock_lines(['SPO-11681', 'HOM-22847', 'ELE-24781'], [3, 12, 0], [10, 12, 4])returns[('SPO-11681', 7), ('ELE-24781', 4)]
callrestock_lines(['A'], [5], [2])returns[]
callrestock_lines([], [], [])returns[]