sort list ascending python code example

Example 1: python sort list in reverse

#1 Changes list
list.sort(reverse=True)
#2 Returns sorted list
sorted(list, reverse=True)

Example 2: how to sort list in ascending order in python

# vowels list
vowels = ['e', 'a', 'u', 'o', 'i']

# sort the vowels
vowels.sort()

# print vowels
print('Sorted list:', vowels)

Example 3: sorting python array

sorted(list, key=..., reverse=...)

Example 4: python sort a list using defined order

>>> sorted(A, key = lambda i: B.index(i[0]))
[[6, 1], [1, 3], [3, 5]]

Example 5: sorting in python

python list sort()