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]
['code', 'geeks', 'ide', 'practice']
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)]
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Python | Sort list of list by specified index
- Python | Sort list according to other list order
- Python | Sort Flatten list of list
- Python | Sort the values of first list using second list
- Sort mixed list in Python
- Python | How to sort a list of strings
- Python | Sort a list of percentage
- Python - Reverse Row sort in Lists of List
- Python | Sort dictionary keys to list
- Sort numeric strings in a list in Python
- Python - Sort Dictionary key and values List
- Python | Alternate Sort in String list
- Python | Sort list containing alphanumeric values
- Python - Sort Records by Kth Index List
- Python | Sort list elements by frequency
- Python | Sort a list according to the second element in sublist
- Python | Sort a List according to the Length of the Elements
- Python | Sort dictionary by value list length
- Python | Sort list of dates given as strings
- Python - Sort List by Dictionary 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 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