Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Searching
Sorting – sort()
6. Sorting in reverse order
Sorting – sorted()
Sorting – reverse() and reversed()
Summary

Instruction

By default, sort() sorts list elements in ascending order. We can change that by specifying an optional argument in the sort() function. Take a look:

books = [
  'Sound of Steel',
  ...
]
books.sort(reverse=True)
print(books)

By adding reverse=True, we get the elements sorted in descending order. Note that reverse is False by default – if you don't provide the argument, you'll always get your elements sorted in ascending order.

Exercise

Create a function named get_sorted_list_desc(input_set) that accepts a set and returns a list with all set elements sorted in descending order. E.g., for the input set {3, 1, 54, 3, 6}, the function should return [54, 6, 3, 1].

Stuck? Here's a hint!

Convert the set into a list first. To create a list from a set, use list().