16.2. Optional reverse parameterΒΆ

The sorted function takes some optional parameters (see the Optional Parameters page). The first optional parameter is a key function, which will be described in the next section. The second optional parameter is a Boolean value which determines whether to sort the items in reverse order. By default, it is False, but if you set it to True, the list will be sorted in reverse order.


For most functions, it is possible to provide optional parameters without keywords, but the sorted function prevents this, so you have to provide keywords for the reverse and key parameters. In this situation, it is more convenient to use the keyword mechanism anyway.

Check Your Understanding

1. Sort the list, lst from largest to smallest. Save this new list to the variable lst_sorted.

You have attempted of activities on this page