购物清单里每一样是 (名字, 价格)。写 cheapest_first(items),按价格从低到高排好,返回名字的列表。价格都不一样。
cheapest_first([("tea", 12), ("cake", 25), ("water", 3)])→['water', 'tea', 'cake']cheapest_first([])→[]def cheapest_first(items):
# 在这里写:用 sorted 和 key,按价格(第 2 个)排
ordered = items
return [name for name, price in ordered]
写好了先点「运行」试试示例,没问题再点「提交」。