List Sort in list is used to sort elements alphabetically or reverse of it as shown below.

Example of List.Sort

a=['apple', 'orange', 'mango', 'guavava']
when we apply sort it will be sorted alphabetically as shown below
a.sort()
a
Output:['apple', 'guavava', 'mango', 'orange']
sort list alphabatically (A To Z)
1.Sort List(A to Z)

To sort reverse of it (Z To A) we will write as shown below

a.sort(reverse=True)

sort list reverse alphabatically (Z To A) using list.sort
2.Sort List(Z to A)

 

By SC

One thought on “List.sort”

Leave a Reply

Your email address will not be published. Required fields are marked *