Kodewick
Start learning →
Basic←→0 / 80

Cheapest first

#002BasicSortingLists4 min

Each thing on the shopping list is (name, price). Write cheapest_first(items) to sort them by price, lowest first, and return the names. No two prices are the same.

Examples
cheapest_first([("tea", 12), ("cake", 25), ("water", 3)])→['water', 'tea', 'cake']
cheapest_first([])→[]
main.py
def cheapest_first(items):
    # your code here: sorted with a key, by the price (the 2nd part)
    ordered = items
    return [name for name, price in ordered]
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.