Thanks to visit codestin.com Credit goes to holypython.com
Let’s check out some exercises that will help understand sorted() function better.
Using sorted() function, sort the list in ascending order.
sorted() function sorts in ascending order by default.
lst2 = sorted(lst1)
Using sorted() function, sort the list from a to z.
sorted() function sorts in ascending order (also a to z in strings) by default.
Using sorted() function sort the list from z to a.
sorted() function sorts in ascending order (also a to z in strings) by default. If you’d like to reverse the sorting order you can simply set reverse parameter to True:
sorted(list, reverse=True)
lst2 = sorted(lst1, reverse = True)