Let’s check out some exercises that will help understand Python’s .sort() method better.

Exercise 11-a

Sort the list in ascending order with .sort() method.


.sort() method will modify the actual list and sort it.

lst.sort()

Exercise 11-b

This time sort the countries in alphabetic order.


.sort() method will modify the actual list and sort it.

lst.sort(reverse = False)

Exercise 11-c

Now sort the list in descending order with .sort() method.


.sort() method can be used with “reverse =” parameter.

lst.sort(reverse = True)

Exercise 11-d

Can you sort the gift list in reverse alphabetic order?


.sort() method can be used with “reverse =” parameter.

gift_list.sort(reverse = True)

Exercise 11-e

Sort the list below in reverse alphabetic order and then assign the last element to the answer_1 variable.


.sort() method can be used with “reverse =” parameter.

NFL.sort(reverse = True)
answer_1 = NFL[-1]

Exercise 11-f

Sort the cities from z to a.


.sort() method can be used with “reverse =” parameter.

muni.sort(reverse = True)

Exercise 11-g

Sort the keys of the dictionary from a to z.


Hint: You might want to create a list of the keys first with the help of a dictionary method.


.keys method of dictionaries returns all the keys of a dictionary.

list() function can be used to construct lists from different types of data.

key_list = list(dict.keys())
key_list.sort()