runtime
121 / 500
question 121 Comprehensions · easy

A price table from pasted lines

A supplier emails price updates as lines of text, SKU, price, typed by hand. Turn them into a lookup the shop can use: SKU to price. A SKU that appears twice was updated, so its later price is the one that counts.

Functionprice_table(lines)
linesa list of texts such as "spo-11681, 7.49": a SKU, a comma, a price; spaces may surround either part
Returnsa dictionary from the SKU (spaces removed at the ends, in capitals) to the price as a float
Rulesa repeated SKU keeps the price from its later line; no lines gives {}
Examples
callprice_table(['spo-11681, 7.49', 'HOM-22847,31', ' ele-24781 ,171.99'])returns{'SPO-11681': 7.49, 'HOM-22847': 31.0, 'ELE-24781': 171.99}
callprice_table(['TOY-54564,26.99'])returns{'TOY-54564': 26.99}
callprice_table([])returns{}

Loading your progress…

A price table from pasted lines — Python practice · Runtime