20 August 2020
Code
Sort ascending:
# Create a list
x = [3,4,1,5,2]
# Sort
x.sort() # default is (reverse=False)
# Output
print(x)
[1, 2, 3, 4, 5]
.
Sort descending:
# Create a list
x = [3,4,1,5,2]
# Sort
x.sort(reverse = True)
# Output
print(x)
[5, 4, 3, 2, 1]
.
Any errors in code above?
Please send a message.