Multiple arguments
In the previous exercise, you identified optional arguments by viewing the documentation with help(). You'll now apply this to change the behavior of the sorted() function.
Have a look at the documentation of sorted() by typing help(sorted) in the IPython Shell.
You'll see that sorted() takes three arguments: iterable, key, and reverse. In this exercise, you'll only have to specify iterable and reverse, not key.
Two lists have been created for you.
Can you paste them together and sort them in descending order?
This exercise is part of the course
Introduction to Python
Exercise instructions
- Use
+to merge the contents offirstandsecondinto a new list:full. - Call
sorted()and onfulland specify thereverseargument to beTrue. Save the sorted list asfull_sorted. - Finish off by printing out
full_sorted.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create lists first and second
first = [11.25, 18.0, 20.0]
second = [10.75, 9.50]
# Paste together first and second: full
full = ____ + ____
# Sort full in descending order: full_sorted
full_sorted = ____
# Print out full_sorted
____