The reverse Parameter
00:00 Every example that we’ve looked at so far has resulted in the returned list being sorted in ascending order. What if you’re trying to make a scoreboard and need the largest numbers first or something in reverse alphabetical order?
then you’ll see that the names are returned in alphabetical order, so
'S'. Now try this again, but this time when you call
sorted() and pass in
names, also say
reverse and set this equal to
01:01 And now you can see that this is in reverse alphabetical order. That’s not too complicated, right? What you should note here is that even though the resulting list is in reverse alphabetical order, the sorting is still based on the first letter of each word.
You’ll get the default behavior that you’ve been seeing before, so you can tell that the default value for
False. In the next video, you’re going to learn how to pass arguments to the
key parameter, which is a little bit more complicated than
reverse, but makes
sorted() incredibly powerful for many different types of data.
Become a Member to join the conversation.