runtime
362 / 500
question 362 Profiling & Optimization · easy

Fix the cached shipping quote

A checkout caches shipping quotes because computing one is slow. Since @cache was added, every checkout crashes with TypeError: unhashable type: 'list'. Fix it so the quote is still cached, and callers can keep passing the cart's weights as a list.

Functionshipping_quote(weights, zone) (called with a list of weights in kg and a zone name)
Returns5.99 plus 1.25 per kg of total weight for "domestic", 24.0 plus 3.5 per kg otherwise
Rulerepeated quotes for the same weights and zone are computed once
Examples
callshipping_quote([2.75, 0.3], 'domestic')returns9.8025
callshipping_quote([1], 'international')returns27.5
callshipping_quote([], 'domestic')returns5.99

Loading your progress…

Fix the cached shipping quote — Python practice · Runtime