Sort List in Python
Sort a list of numbers in ascending order.
BeginnerList ProgramsExample 9 of 25
sort-list.py
Run in browser1# Program to sort a list of numbers23numbers = list(map(float, input("Enter numbers separated by space: ").split()))45numbers.sort()67print("Sorted list:", numbers)
Output
Enter numbers separated by space: 3 1 4 2 Sorted list: [1.0, 2.0, 3.0, 4.0]
What's going on
We use the in-place .sort() method to sort the list in ascending order.