Articles → Python → Sorted Method In Python
Sorted Method In Python
Purpose
Example
# Sorting list
li = [2,3,1,4,5]
print("Sorted list:", sorted(li))
# Sorting tuple
tu = (8,3,4,5,6)
print("Sorted tuple:", sorted(tu))
Output
Sorting The Sequence In Reverse Order
# Sorting list
li = [2,3,1,4,5]
print("Sorted list:", sorted(li, reverse = True))
# Sorting tuple
tu = (8,3,4,5,6)
print("Sorted tuple:", sorted(tu, reverse = True))
Output