sort the following list of numbers: [1, 3, 4, 2, 5] in python

To sort the list [1, 3, 4, 2, 5] in ascending order in Python, you can use the built-in sort() function of Python which modifies the original list.

main.py
numbers = [1, 3, 4, 2, 5]
numbers.sort()
print(numbers)
56 chars
4 lines

Output:

main.py
[1, 2, 3, 4, 5]
16 chars
2 lines

If you want to create a new sorted list without changing the original list, you can use the built-in sorted() function.

main.py
numbers = [1, 3, 4, 2, 5]
sorted_numbers = sorted(numbers)
print(sorted_numbers)
81 chars
4 lines

Output:

main.py
[1, 2, 3, 4, 5]
16 chars
2 lines

gistlibby LogSnag