Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

sort a list python

"""Sort in ascending and descending order"""
list_test = [2, 1, 5, 3, 4]

#ascending is by default for sort
#Time Complexity: O(nlogn)
list_test.sort()

#For descending order
#Time Complexity: O(nlogn)
list_test.sort(reverse=True)

#For user-define order
list_test.sort(key=..., reverse=...) 
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #sort #list #python
ADD COMMENT
Topic
Name
2+2 =