1 00:00:00,630 --> 00:00:01,080 All right. 2 00:00:01,080 --> 00:00:02,920 It feels like it's never going to end. 3 00:00:02,940 --> 00:00:08,970 We have so many methods with lists, but like I said, lists have a lot of methods because you can do 4 00:00:08,970 --> 00:00:09,950 a lot with them. 5 00:00:09,960 --> 00:00:11,310 It seems like a lot right now. 6 00:00:11,310 --> 00:00:13,800 But trust me, these are going to become second nature. 7 00:00:13,800 --> 00:00:15,000 So hang in there. 8 00:00:15,000 --> 00:00:16,530 I have a few more to show you. 9 00:00:17,070 --> 00:00:20,850 The next one is called Sort. 10 00:00:21,790 --> 00:00:25,180 Guess what sort is going to do if I click Run? 11 00:00:27,290 --> 00:00:28,670 I get none. 12 00:00:29,270 --> 00:00:29,630 Hmm. 13 00:00:29,720 --> 00:00:37,440 But remember, sort of sorts the list, as you can imagine, in place that means and modifies the list. 14 00:00:37,460 --> 00:00:45,590 So if I remove this up to here and then do sort or do basket and I click Run. 15 00:00:47,290 --> 00:00:52,560 Look that I get a sorted list where Dee was moved in front of E. 16 00:00:53,050 --> 00:00:57,130 If I add let's say X at the beginning here. 17 00:00:58,560 --> 00:00:59,940 And I click Run. 18 00:01:00,790 --> 00:01:03,230 It's going to move the ex all the way to the end. 19 00:01:03,250 --> 00:01:06,880 It's going to sort the list in place for me again. 20 00:01:06,880 --> 00:01:13,120 If I hover over it, sees that it's going to not return anything, which is why our print initially 21 00:01:13,120 --> 00:01:13,660 didn't work. 22 00:01:13,660 --> 00:01:18,790 We had to print our basket, not whatever this produces, which it doesn't produce anything. 23 00:01:19,970 --> 00:01:20,260 Hmm. 24 00:01:20,270 --> 00:01:21,620 But what about this one? 25 00:01:21,620 --> 00:01:25,820 If we go to built in functions, I have something called sorted. 26 00:01:26,270 --> 00:01:35,420 And if I do sorted and because it's a function, not a method, I can do sorted, dot or basket. 27 00:01:35,690 --> 00:01:37,370 So around. 28 00:01:38,180 --> 00:01:39,740 The brackets, just like print. 29 00:01:40,130 --> 00:01:41,810 If I run this. 30 00:01:42,380 --> 00:01:44,440 All right, nothing has changed. 31 00:01:44,450 --> 00:01:49,430 But what if I remove this and put it in here? 32 00:01:50,160 --> 00:01:54,630 If I click run, I get a, b, c, d, e, x. 33 00:01:55,470 --> 00:01:57,330 What if I comment this out? 34 00:01:58,720 --> 00:02:00,610 So that we're not sorting it anymore. 35 00:02:00,610 --> 00:02:02,980 We just have the basket and then we run this sorted. 36 00:02:03,950 --> 00:02:05,390 Function if I run. 37 00:02:07,660 --> 00:02:08,560 Did you see that? 38 00:02:09,630 --> 00:02:10,590 Sorted. 39 00:02:10,620 --> 00:02:11,630 I know it's confusing. 40 00:02:11,640 --> 00:02:13,010 Why do they even have to? 41 00:02:13,020 --> 00:02:16,620 But sorted produces a new array. 42 00:02:18,420 --> 00:02:23,430 So if I do print basket here and I click run. 43 00:02:25,620 --> 00:02:29,070 The basket hasn't been modified. 44 00:02:30,580 --> 00:02:32,770 The basket still remains the same. 45 00:02:32,770 --> 00:02:34,570 It's this one over here that's not sorted. 46 00:02:34,810 --> 00:02:39,760 Sorted, on the other hand, doesn't modify the basket in place. 47 00:02:39,760 --> 00:02:43,960 Instead, it creates a new copy of the basket and sorts it. 48 00:02:44,410 --> 00:02:46,630 It's almost as if we're doing this. 49 00:02:46,870 --> 00:02:57,130 We're saying new basket equals basket, and then we're going to copy that basket, remember list slicing 50 00:02:57,490 --> 00:03:07,870 and then we're performing New Basket sort on this new list so that if I do New Basket and I click Run. 51 00:03:09,490 --> 00:03:11,080 We get the same thing. 52 00:03:11,720 --> 00:03:19,160 So you have to be careful of certain actions that perform an action in place or create a completely 53 00:03:19,160 --> 00:03:20,930 new list to begin with. 54 00:03:22,590 --> 00:03:28,500 By the way, there's also, instead of this, a dot copy method that we can use. 55 00:03:28,890 --> 00:03:30,330 And if I run this. 56 00:03:31,180 --> 00:03:31,540 Again. 57 00:03:31,540 --> 00:03:32,710 We get the same thing. 58 00:03:32,740 --> 00:03:33,520 Copy. 59 00:03:33,520 --> 00:03:35,130 Just as the name suggests. 60 00:03:35,140 --> 00:03:38,740 Copy the list for us and returns for us a new list. 61 00:03:40,060 --> 00:03:46,270 All right, one last one and that is basket dot reverse. 62 00:03:48,500 --> 00:03:50,450 What do you think this does based on the name? 63 00:03:51,930 --> 00:03:57,090 Well, if I check out the basket here and click Run. 64 00:03:58,960 --> 00:04:00,250 Is that what you expected? 65 00:04:01,700 --> 00:04:04,790 It reverses the basket. 66 00:04:05,810 --> 00:04:06,650 In place. 67 00:04:07,320 --> 00:04:09,610 But notice that it's not like sort. 68 00:04:09,630 --> 00:04:10,590 It's not sorting. 69 00:04:10,590 --> 00:04:16,070 It's simply switching all the indexes into opposite sides. 70 00:04:16,079 --> 00:04:18,510 So DX is now index of zero. 71 00:04:18,540 --> 00:04:20,790 E is now index of one. 72 00:04:20,910 --> 00:04:23,530 Index of two three, so on and so forth. 73 00:04:23,550 --> 00:04:26,550 So you can see here that it doesn't actually sort it. 74 00:04:26,790 --> 00:04:32,730 Instead, what we might want to do is sort first, then reverse. 75 00:04:32,730 --> 00:04:34,350 And if we click Run. 76 00:04:35,230 --> 00:04:39,730 We have a sorted, reversed basket. 77 00:04:40,270 --> 00:04:43,900 This is a little tricky one that some interviewers might ask. 78 00:04:44,440 --> 00:04:45,000 All right. 79 00:04:45,010 --> 00:04:46,570 Good job getting this far. 80 00:04:46,600 --> 00:04:48,880 We're almost done with lists. 81 00:04:49,120 --> 00:04:50,800 So I'll see you in the next video. 82 00:04:51,010 --> 00:04:51,460 Bye bye.