← Back to challenges

Drink Sorting

PythonHardobjectssorting

Instructions

You will be given a list of drinks, with each drink being a dictionary with two properties: name and price. Create a function that has the drinks list as an argument and return the drinks dictionaries sorted by price in ascending order.

Assume that the following array of drink objects needs to be sorted:

drinks = [
  {"name": "lemonade", "price": 50},
  {"name": "lime", "price": 10}
]

The output of the sorted drinks object will be:

Examples

sort_drinks_by_price(drinks) ➞ [{name: "lime", price: 10}, {name: "lemonade", price: 50}]

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Reverse Coding Challenge #1