question 182 Files & Directories · easy
Fix the stock loader
load_stock should read a stock export into a dictionary from SKU to quantity, but it crashes on the real file with ValueError: not enough values to unpack. Fix it so it meets the contract below. There is more than one problem.
Function
load_stock(path)Filea header line
sku,qty, then one SKU,quantity line per product; blank lines may appearReturnsa dictionary
{sku: quantity} with whole-number quantities, e.g. {'HOM-52782': 4, 'BOO-58412': 0, 'GRO-63674': 12} for stock.csvRulesthe header is not a product; blank lines are skipped; spaces around either value are ignored
Examples
callload_stock('stock.csv')returns{'HOM-52782': 4, 'BOO-58412': 0, 'GRO-63674': 12}