Sorting lists
Your food delivery platform is expanding as new restaurants join daily. You have a restaurants list with restaurant names and a cooking_times list showing average meal preparation times in minutes. Your team needs both lists sorted to identify top-performing restaurants and improve delivery logistics.
Let's use another built-in function to handle this request.
This exercise is part of the course
Intermediate Python for Developers
Exercise instructions
- Sort
restaurantsalphabetically, saving asrestaurants_sorted. - Sort
cooking_timesfrom fastest to slowest, saving ascooking_times_sorted.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
restaurants = ["Sushi Central", "Burger Hub", "Taco Town", "Pizza Palace"]
cooking_times = [30, 25, 35, 40, 28, 32, 29, 31, 12, 55]
# Sort restaurant names alphabetically
restaurants_sorted = ____(____)
# Sort cooking times from fastest to slowest
cooking_times_sorted = ____(____)
print("Restaurants (A–Z):", restaurants_sorted)
print("Cooking times (ascending):", cooking_times_sorted)