시작하기무료로 시작하기

리스트 정렬하기

새로운 레스토랑이 매일 입점하면서 음식 배달 플랫폼이 빠르게 성장하고 있습니다. 레스토랑 이름이 담긴 restaurants 리스트와 분 단위 평균 조리 시간이 담긴 cooking_times 리스트가 있습니다. 팀에서는 두 리스트를 정렬해 우수 레스토랑을 파악하고 배달 물류를 개선하고자 합니다.

이번에는 내장 함수를 활용해 이 작업을 처리해 보겠습니다.

이 연습은 강의의 일부입니다

개발자를 위한 Python 중급

강의 보기

연습 안내

  • restaurants를 알파벳순으로 정렬한 후 restaurants_sorted에 저장하세요.
  • cooking_times를 가장 빠른 순서에서 느린 순서로 정렬한 후 cooking_times_sorted에 저장하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

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)
코드 편집 및 실행