Sort a List

Sort a List

Tags: Data Structures

Credit: CodingChallenge

Difficulty: Beginner

Type: Text

Category: Practice

Time Allowed: 5 s

Description:

Write a function that takes a list of numbers and returns a new list with the elements sorted in ascending order. This problem is designed to help you practice using built-in sorting methods. The function should accept one parameter and return the sorted list.

Constraints:

  • The input will be a list of numbers (integers or floats).
  • The list can be empty, in which case the returned list should also be empty.
  • Do not implement a sorting algorithm; use the built-in sorting functions.
  • The function should return a list with the elements sorted in ascending order.

Example:

  • Input: [3, 1, 4, 1, 5, 9]
  • Output: [1, 1, 3, 4, 5, 9]

Test Case Input Expected Output
1 [] []
2 [3, 1, 4, 1, 5, 9] [1, 1, 3, 4, 5, 9]
3 [-2, -5, -3, -1, -4] [-5, -4, -3, -2, -1]
4 [5] [5]
5 [1.5, 2.5, 0.5] [0.5, 1.5, 2.5]
6 [3, 3, 3] [3, 3, 3]
7 [100, 10, 1000, 1] [1, 10, 100, 1000]

Please register or login to submit solutions to challenges.