How do you reverse sort a list in Python?

You can use the sort method for lists to sort in reverse order. By default, the reverse parameter is set to False, which means it sorts in ascending order. Setting it to True will sort the list in descending order.

Here is an example code:

my_list = [3, 1, 4, 1, 5, 9, 2, 6, 5]
my_list.sort(reverse=True)
print(my_list)

The output is: [9, 6, 5, 5, 4, 3, 2, 1, 1]

bannerAds