question 383 Async Python · easy
Price a basket with overlapping lookups
A checkout needs every item's price and the customer's tax rate, each from a different service. Write checkout_total(skus, get_price, get_tax_rate, region) that runs all these lookups at the same time and returns the total including tax.
Coroutine
async def checkout_total(skus, get_price, get_tax_rate, region)Returns
sum(prices) * (1 + rate) where each price is await get_price(sku) and the rate is await get_tax_rate(region)Ruleevery lookup overlaps: the total time is the slowest single lookup