The sort function can be used to sort a list in ascending, descending or user defined order.
To sort the list in ascending order.
This will sort the given list in ascending order.
This function can be used to sort list of integers, floating point number, string and others.
[1, 2, 3, 4]
To sort the list in descending order.
This will sort the given list in descending order.
[4, 3, 2, 1]
Sorting user using user defined order.
list_name.sort(key=…, reverse=…) – it sorts according to user’s choice
[(1, 1), (1, 2), (3, 3)] [(3, 3), (1, 2), (1, 1)]
- Python | Sort Flatten list of list
- Python | Sort list according to other list order
- Python | Sort list of list by specified index
- Python | Sort the values of first list using second list
- Python | Sort a list of percentage
- Python | How to sort a list of strings
- Python | Sort list of numbers by sum of their digits
- Python | Sort all sublists in given list of strings
- Python | Sort the list alphabetically in a dictionary
- Python | Sort numeric strings in a list
- Python | Sort a list according to the second element in sublist
- Python | Sort list containing alphanumeric values
- Python | Sort list elements by frequency
- Python | Sort a List according to the Length of the Elements
- Python | Sort list of dates given as strings
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.