← Back to challenges

Sort Numbers in Ascending Order

PythonMediumsortingarraysnumbers

Instructions

Create a function that takes a list of numbers and returns a new list, sorted in ascending order (smallest to biggest).

  • Sort numbers list in ascending order.
  • If the function's argument is None or an empty list, return an empty list.
  • Return a new array of sorted numbers.

Examples

sort_nums_ascending([1, 2, 10, 50, 5]) ➞ [1, 2, 5, 10, 50]

sort_nums_ascending([80, 29, 4, -95, -24, 85]) ➞ [-95, -24, 4, 29, 80, 85]

sort_nums_ascending([]) ➞ []

Notes

Test input can be positive or negative.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Find the Index