1 00:00:00,660 --> 00:00:02,950 All right, it feels like it's never going to end. 2 00:00:02,970 --> 00:00:08,970 We have so many methods with less, but like I said, lists have a lot of methods because you can do 3 00:00:08,970 --> 00:00:09,930 a lot with them. 4 00:00:09,940 --> 00:00:11,340 It seems like a lot right now. 5 00:00:11,340 --> 00:00:13,820 But trust me, these are going to become second nature. 6 00:00:13,830 --> 00:00:14,990 So hang in there. 7 00:00:15,030 --> 00:00:16,380 I have a few more to show you. 8 00:00:17,220 --> 00:00:20,700 The next one is called SORT. 9 00:00:21,810 --> 00:00:24,990 Guess what sort is going to do if I click run? 10 00:00:27,310 --> 00:00:29,500 I get none, hmm. 11 00:00:29,860 --> 00:00:37,000 But remember, sort of sorts the list, as you can imagine, in place, that means and modifies the 12 00:00:37,000 --> 00:00:37,360 list. 13 00:00:37,580 --> 00:00:45,430 So if I remove this Opta here and then do sort or do basket and I click run. 14 00:00:47,370 --> 00:00:56,370 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 15 00:00:56,370 --> 00:00:56,970 beginning here. 16 00:00:58,640 --> 00:00:59,750 And I click run. 17 00:01:00,840 --> 00:01:06,900 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, 18 00:01:06,900 --> 00:01:13,140 if I hover over it, sees that it's going to not return anything, which is why our print initially 19 00:01:13,140 --> 00:01:13,680 didn't work. 20 00:01:13,680 --> 00:01:18,630 We had to print our basket, not whatever this produces, which it doesn't produce anything. 21 00:01:19,930 --> 00:01:26,830 Hmm, but what about this one, if we go to built in functions, I have something called sorted and 22 00:01:26,830 --> 00:01:35,200 if I do sorted and because it's a function, not a method, I can do sorted dot or basket. 23 00:01:35,860 --> 00:01:37,180 So around. 24 00:01:38,220 --> 00:01:42,670 The BRAK is just like print if I run this right. 25 00:01:42,810 --> 00:01:49,310 Nothing has changed, but what if I remove this and put it in here? 26 00:01:50,230 --> 00:01:57,130 If I click run, I get A, B, C, D, e, x, hmm, what if I comment this out? 27 00:01:58,790 --> 00:02:02,810 So that we're not sorting it anymore, we just have the basket and then we run this sorted. 28 00:02:09,740 --> 00:02:10,470 Sorted. 29 00:02:10,640 --> 00:02:11,640 I know it's confusing. 30 00:02:11,660 --> 00:02:16,460 Why do they even have to, but sorted produces a new array. 31 00:02:18,530 --> 00:02:21,200 So if I do print basket here. 32 00:02:22,060 --> 00:02:23,230 And I click run. 33 00:02:25,690 --> 00:02:28,930 The basket hasn't been modified. 34 00:02:30,630 --> 00:02:32,740 The basket still remains the same. 35 00:02:32,760 --> 00:02:39,240 It's this one over here that's not sorted, sorted, on the other hand, doesn't modify the basket in 36 00:02:39,240 --> 00:02:39,690 place. 37 00:02:39,810 --> 00:02:43,760 Instead, it creates a new copy of the basket and sorts it. 38 00:02:44,490 --> 00:02:46,410 It's almost as if we're doing this. 39 00:02:47,040 --> 00:02:54,870 We're saying new basket equals basket and then we're going to copy that basket. 40 00:02:54,900 --> 00:03:04,620 Remember list slicing and then we're performing new basket dot sort on this new list so that if I do 41 00:03:05,610 --> 00:03:07,710 New Basket and I click run. 42 00:03:09,620 --> 00:03:10,910 We get the same thing. 43 00:03:11,830 --> 00:03:19,150 So you have to be careful of certain actions that perform an action in place or create a completely 44 00:03:19,150 --> 00:03:20,770 new list to begin with. 45 00:03:22,720 --> 00:03:30,100 By the way, there's also, instead of this, a dot copy method that we can use and if I run this. 46 00:03:31,160 --> 00:03:37,460 Again, we get the same thing, Kopi, just as the name suggests, copied the list for us and returns 47 00:03:37,460 --> 00:03:38,570 for us a new list. 48 00:03:40,100 --> 00:03:46,070 All right, one last one, and that is basket dot reverse. 49 00:03:48,630 --> 00:03:50,280 What do you think this does based on the name? 50 00:03:52,030 --> 00:03:56,950 Well, if I check out the basket here and click Run. 51 00:03:58,920 --> 00:04:00,060 Is that what you expected? 52 00:04:01,720 --> 00:04:04,630 It reverses the basket. 53 00:04:05,800 --> 00:04:06,430 Emplace. 54 00:04:07,450 --> 00:04:15,070 But notice that it's not like sort it's not sorting, it's simply switching all the indexes into opposite 55 00:04:15,430 --> 00:04:15,900 sides. 56 00:04:16,210 --> 00:04:23,400 So D is now index of zero, E is now index of one, index of two, three, so on and so forth. 57 00:04:23,710 --> 00:04:26,350 So you can see here that it doesn't actually sort it. 58 00:04:26,920 --> 00:04:34,150 Instead, what we might want to do is sort first, then reverse and if we click, run. 59 00:04:35,370 --> 00:04:43,740 We have a sorted, reversed basket, this is a little tricky one that some interviewers might ask. 60 00:04:44,490 --> 00:04:46,340 All right, good job getting this far. 61 00:04:46,770 --> 00:04:51,350 We're almost done with lists, so I'll see you in the next video, Pabai.