how to sort in greatest to least python 1

how to sort in greatest to least python

myList1 = [1, 2, 3, 4, 5]

# inplace sort() greatest to least
myList1.sort(reverse=True)

# deep copy sorted() greatest to least
myList2 = sorted(myList1, reverse=True)

Here is what the above code is Doing:
1. myList1 = [1, 2, 3, 4, 5]
2. myList1.sort(reverse=True)
3. myList2 = sorted(myList1, reverse=True)

myList1 is now [5, 4, 3, 2, 1]
myList2 is [5, 4, 3, 2, 1]

Similar Posts