Question: In the previous exercise, you identified optional arguments by viewing the documentation with help ( ) . You'll now apply this to change the behavior
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 helpsorted in the IPython Shell.
You'll see that sorted takes three arguments: iterable, key, and reverse.
keyNone means that if you don't specify the key argument, it will be None. reverseFalse means that if you don't specify the reverse argument, it will be False, by default.
In this exercise, you'll only have to specify iterable and reverse, not key. The first input you pass to sorted will be matched to the iterable argument, but what about the second input? To tell Python you want to specify reverse without changing anything about key, you can use to assign it a new value:
sorted reverse
Two lists have been created for you. Can you paste them together and sort them in descending order?
Note: For now, we can understand an iterable as being any collection of objects, eg a List.
Instructions
XP
Use to merge the contents of first and second into a new list: full.
Call sorted on full and specify the reverse argument to be True. Save the sorted list as fullsorted.
Finish off by printing out fullsorted.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
