array sort in python code example
Example 1: sort array python
array = [1, 2, 3, 19, 11, 90, 0]
array.sort()
print(array)
Example 2: how to sort list in descending order in python
#1 Changes list
list.sort(reverse=True)
#2 Returns sorted list
sorted(list, reverse=True)
Example 3: sort an array python
#List
myList = [1,5,3,4]
myList.sort()
print(myList)
#[1,3,4,5]
Example 4: sort in python'
arr = [1,4,2,7,5,6]
#sort in ascending order
arr = arr.sort()
#sort in descending order
arr = arr.sort(reverse = True)
Example 5: sorting python array
sorted(list, key=..., reverse=...)
Example 6: sort list in python
List_name.sort()
This will sort the given list in ascending order.