sort list python descending code example
Example 1: python sort list in reverse order
sorted(list_name, reverse=True)
list_name.sort(reverse=True)
Example 2: python sort list in reverse
list.sort(reverse=True)
sorted(list, reverse=True)
Example 3: python sort a list by a custom order
list_to_sort = [('U', 23), ('R', 42), ('L', 17, 'D')]
custom_sort_order = ['R', 'D', 'L', 'U']
sorted(list_to_sort, key=lambda list_to_sort: custom_sort_order.index(list_to_sort[0]))
--> [('R', 42), ('L', 17, 'D'), ('U', 23)]
Example 4: how to sort a list descending python
A.sort(reverse = True)
Example 5: sorting python array
sorted(list, key=..., reverse=...)