sorting function in python code example
Example 1: how to sort a list descending python
A.sort(reverse = True)
Example 2: sort in python'
arr = [1,4,2,7,5,6]
arr = arr.sort()
arr = arr.sort(reverse = True)
Example 3: python sort
nums = [4,8,5,2,1]
sorted_nums = sorted(nums)
print(sorted_nums)
print(nums)
nums.sort()
print(nums)
Example 4: list sort python
>>> names = ['Harry', 'Suzy', 'Al', 'Mark']
>>> sorted(names)
['Al', 'Harry', 'Mark', 'Suzy']
>>> sorted(names, reverse=True)
['Suzy', 'Mark', 'Harry', 'Al']