How to Reverse a List in Python?
Hello Friends,
This post is focused on how to reverse sort python list. Here you will learn how to reverse order of list python. you will learn how to reverse sort in python list. we will help you to give an example of how to reverse python list.
There are several ways to reverse order python list. i will give you simple three example to reverse sort with python list. we will use reverse(), sort() and [::-1] to sorting descending order to python list.
Example 1:
main.py
myList = [1, 2, 3, 4, 5] # python list reverse order myList.reverse() print(myList)
Output:
[5, 4, 3, 2, 1]
Example 2:
main.py
myList = [1, 2, 3, 4, 5] # python list reverse order myList = myList[::-1] print(myList)
Output:
[5, 4, 3, 2, 1]
Example 3:
main.py
myList = [1, 2, 3, 4, 5] # python list reverse order myList.sort(reverse=True) print(myList)
Output:
[5, 4, 3, 2, 1]
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Convert JSON Array to Python List Example
- Python Smallest and Largest Numbers in a List Example
- How to Get Smallest Number in List Python?
- How to Get Largest Number in List Python?
- Python Remove Character from List of Strings Example
- How to Replace Value in Python List?
- Python List Find and Replace Element Example
- Python Generate List of Random Strings Example
- Python Generate List of Random Numbers Between 0 and 1 Example
- How to Get Last 2, 3, 4, 5, 10, etc Elements from List in Python?
- How to Convert List to Uppercase in Python?
- How to Convert String into List in Python?
- How to Remove Duplicate Values from List in Python?
- How to Get Unique Elements from List in Python?