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]
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!
More Posts related to Python,
- Python List of Lists with Examples
- Fix: ERROR: Could not find a version that satisfies the requirement tkinter (from versions: none) ERROR: No matching distribution found for tkinter
- How to Convert Python Notebook .ipynb (JSON) to Executable .py Module
- ModuleNotFoundError: No module named qdarkstyle.colorsystem [Python]
- Python: Pandas Merge Indicator (Left, Right and Both) Example
- Fix: EOFError Exception in Python
- How to URL Decode a Query String in Python
- How to take user input from the console in a Python program
- Compare two lists in Python and return matches
- How to change the Python Default version
- Fix: KeyError: exception in Python
- How to get the Execution Time of A Python Program
- Fix: ModuleNotFoundError: No module named boto3 [Python]
- How to get unique values from a list in Python
- How to pip install Python Modules in VSCode
- Python: Fix - TypeError: NoneType object is not iterable
- How to delete a file using Python code example
- How to create a dictionary comprehension in Python
- Python: Get just the filename without extension using Path
- How to comment out a block of code in Python
- How to add two float numbers in Python
- Python: How to POST Json Data with HTTP Request
- Get MD5 Hash as Checksum of a String in Python
- Python - Convert float to String
- How to Parse XML String in Python
More Posts:
- How to FTP using Mac Terminal - MacOS
- HandsOn: Create Queue in RabbitMQ using Management UI and Command Line rabbitmqctl - HowTos
- Tutorial : Simple Lightweight Pure CSS based Vertical Navigation Menu - CSS
- Fix: 403 Forbidden/Access Denied Error during Windows Software Updates - Windows
- Ways to Open New Tabs or New Windows on Windows 11 Notepad - Windows-11
- Running Android Lint has encountered a problem NullPointerException Error - Android
- How to make use of SQLite Module in Python? - Python
- Launch Notepad++ html document in any web browser - NotepadPlusPlus