Optional reverse parameter

The sorted function takes some optional parameters (see Optional parameters). 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.

Note

This is a situation where it is convenient to use the keyword mechanism for providing optional parameters. It is possible to provide the value True for the reverse parameter without naming that parameter, but then we would have to provide a value for the second parameter as well, rather than allowing the default parameter value to be used. We would have had to write sorted(L2, None, True). That’s a lot harder for humans to read and understand.

Next Section - Optional key parameter