Use sort() with reverse=True to sort a list in reverse order in Python. The sort() method sorts the list ascending by default.
Python sort reverse example
Simple example code use reverse attribute in the sort method. Set it equal to True to sort the list in reverse order in place.
a_list = [1, 2, 3] a_list.sort(reverse=True) print(a_list)
Do comment if you have any doubts and suggestions on this Python sort tutorial.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.