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 list according to other list order
- Python | Sort Flatten list of list
- Python | Sort list of list by specified index
- 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 list elements by frequency
- Python | Sort the list alphabetically in a dictionary
- Python | Sort given list of dictionaries by date
- Python | Sort a List according to the Length of the Elements
- Python | Sort numeric strings in a list
- Python | sort list of tuple based on sum
- Python | Sort dictionary by value list length
- Python | Sort all sublists in given list of 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.
Improved By : shubham_singh