Python: Sort List in Descending Order


In order to sort a list of elements in descending order, we can make use of the sort() method by passing the option reverse=True

Example:
list_of_numbers = [22, 45, 245, 64, 345, 66, 33, 68, 24, 27, 78]

list_of_numbers.sort(reverse=True)

print(list_of_numbers)
Output:
[345, 245, 78, 68, 66, 64, 45, 33, 27, 24, 22]
Python- Sort List in Descending Order
Read Documentaion:

List Objects - List.sort(): https://docs.python.org/3/library/stdtypes.html#list.sort

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright ยฉ Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap