All right, it feels like it's never going to end.
We have so many methods with less, but like I said, lists have a lot of methods because you can do
a lot with them.
It seems like a lot right now.
But trust me, these are going to become second nature.
So hang in there.
I have a few more to show you.
The next one is called SORT.
Guess what sort is going to do if I click run?
I get none, hmm.
But remember, sort of sorts the list, as you can imagine, in place, that means and modifies the
list.
So if I remove this Opta here and then do sort or do basket and I click run.
Look at that, I get a sorted list where D was moved in front of me, if I had, let's say, X at the
beginning here.
And I click run.
It's going to move the axe all the way to the end, it's going to sort the list in place for me again,
if I hover over it, sees that it's going to not return anything, which is why our print initially
didn't work.
We had to print our basket, not whatever this produces, which it doesn't produce anything.
Hmm, but what about this one, if we go to built in functions, I have something called sorted and
if I do sorted and because it's a function, not a method, I can do sorted dot or basket.
So around.
The BRAK is just like print if I run this right.
Nothing has changed, but what if I remove this and put it in here?
If I click run, I get A, B, C, D, e, x, hmm, what if I comment this out?
So that we're not sorting it anymore, we just have the basket and then we run this sorted.
Sorted.
I know it's confusing.
Why do they even have to, but sorted produces a new array.
So if I do print basket here.
And I click run.
The basket hasn't been modified.
The basket still remains the same.
It's this one over here that's not sorted, sorted, on the other hand, doesn't modify the basket in
place.
Instead, it creates a new copy of the basket and sorts it.
It's almost as if we're doing this.
We're saying new basket equals basket and then we're going to copy that basket.
Remember list slicing and then we're performing new basket dot sort on this new list so that if I do
New Basket and I click run.
We get the same thing.
So you have to be careful of certain actions that perform an action in place or create a completely
new list to begin with.
By the way, there's also, instead of this, a dot copy method that we can use and if I run this.
Again, we get the same thing, Kopi, just as the name suggests, copied the list for us and returns
for us a new list.
All right, one last one, and that is basket dot reverse.
What do you think this does based on the name?
Well, if I check out the basket here and click Run.
Is that what you expected?
It reverses the basket.
Emplace.
But notice that it's not like sort it's not sorting, it's simply switching all the indexes into opposite
sides.
So D is now index of zero, E is now index of one, index of two, three, so on and so forth.
So you can see here that it doesn't actually sort it.
Instead, what we might want to do is sort first, then reverse and if we click, run.
We have a sorted, reversed basket, this is a little tricky one that some interviewers might ask.
All right, good job getting this far.
We're almost done with lists, so I'll see you in the next video, Pabai.