Sorting and Reversing
Learn about sorting and reversing lists.
We'll cover the following...
Using list methods
Let’s learn how to reverse and sort lists.
Press + to interact
lst = [10, 2, 0, 50, 4]lst.reverse( )print(lst) # prints [4, 50, 0, 2, 10]lst.sort( )print(lst) # prints [0, 2, 4, 10, 50]lst.sort(reverse = True) # sort items in reverse orderprint(lst) # prints [50, 10, 4, 2, 0]
Note: The
reverse()
...