print in ascending order python code example

Example 1: python sort list

# sort() will change the original list into a sorted list
vowels = ['e', 'a', 'u', 'o', 'i']
vowels.sort()
# Output:
# ['a', 'e', 'i', 'o', 'u']

# sorted() will sort the list and return it while keeping the original
sortedVowels = sorted(vowels)
# Output:
# ['a', 'e', 'i', 'o', 'u']

Example 2: how to sort a list descending python

# defning A as a list
A.sort(reverse = True)

Example 3: how to sort a list in python

old_list = [3,2,1]
old_list.sort()

Example 4: sorting in python

python list sort()