runtime
182 / 500
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.

Functionload_stock(path)
Filea header line sku,qty, then one SKU,quantity line per product; blank lines may appear
Returnsa dictionary {sku: quantity} with whole-number quantities, e.g. {'HOM-52782': 4, 'BOO-58412': 0, 'GRO-63674': 12} for stock.csv
Rulesthe 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}

Loading your progress…

Fix the stock loader — Python practice · Runtime