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 is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap