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 of list by specified index
- Python | Sort list according to other list order
- Python | Sort the values of first list using second list
- Python | How to sort a list of strings
- Sort mixed list in Python
- Python | Sort a list of percentage
- Python | Sort numeric strings in a list
- Python | Sort dictionary keys to list
- Python | Sort list of dates given as strings
- Python | Sort all sublists in given list of strings
- Python | Sort list of numbers by sum of their digits
- Python - Reverse Row sort in Lists of List
- Python | Sort a list according to the second element in sublist
- Python | Sort list containing alphanumeric values
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.
Improved By : shubham_singh