Welcome back. What if we don't want to sort from the smallest item to the largest,
but instead we want the reverse order? Well, that's easy.
You've already seen how you can reverse a list,
was actually a reverse function or you could do a list accumulation.
But, it's actually even easier than that because we can
specify an optional parameter for the sorted function called reverse.
That's an optional parameter its default value,
if you don't provide a value for it, it is false.
But if you pass the value true in,
you get the list back in the opposite order,
you can see that on line number two.
In addition to saying,
what list we want to sort,
we're also saying that the reverse parameter should get the value true.
When we do that, we'll get the things in reverse order,
Cherry, Blueberry, then Apple.
I hope I'm not making it too hungry with these examples.
So, this reverse equals true is just passing a parameter,
the usual thing that we've seen before for functions.
The actual value that we're passing in here,
the word true is just a Boolean value,
if you'll recall from when we were doing Boolean values.
I could change this.
Instead of passing the Boolean value true,
I could pass the Boolean value false,
and I would say, "Don't give this back in reverse order, not reversed."
So, we would get Apple, Blueberry, and Cherry.
Now, false is the default value for the reverse parameter.
So, if I leave it out entirely,
I get the same thing that I would get is if I say, "Reverse equals false."
So, if I don't want it reversed,
I don't have to say it.
If I do want it reversed,
I have to say "Reverse equals true."
I get it in the reverse order.
So, that's sorting a sequence in the opposite or the reverse order.
I'll see you next time when we specify a custom order for sorting,
based on some property of the items that are getting sorted.