Sorting the List in Ascending and Descending order in Python

Source code :

a=[1,3,5,3,4,2,7,9,8]

a.sort()
print("Ascending order is ",a)

a.sort(reverse=True)
print("Descending order is ",a)

Output :

Ascending order is  [1, 2, 3, 3, 4, 5, 7, 8, 9]
Descending order is  [9, 8, 7, 5, 4, 3, 3, 2, 1]

Output :


                

Comments :