1 00:00:00,790 --> 00:00:03,190 The following content is provided under a Creative 2 00:00:03,190 --> 00:00:04,730 Commons license. 3 00:00:04,730 --> 00:00:07,030 Your support will help MIT OpenCourseWare 4 00:00:07,030 --> 00:00:11,390 continue to offer high-quality educational resources for free. 5 00:00:11,390 --> 00:00:13,990 To make a donation or view additional materials 6 00:00:13,990 --> 00:00:17,860 from hundreds of MIT courses, visit MIT OpenCourseWare 7 00:00:17,860 --> 00:00:18,810 at ocw.mit.edu. 8 00:00:24,037 --> 00:00:25,370 ANA BELL: Let's walk through it. 9 00:00:29,560 --> 00:00:30,780 We have three lists. 10 00:00:30,780 --> 00:00:33,220 L1 is equal to [re]. 11 00:00:33,220 --> 00:00:36,630 L2 is equal to [mi]. 12 00:00:36,630 --> 00:00:40,570 L3 is equal to [do]. 13 00:00:40,570 --> 00:00:46,120 L4 is equal to-- let's just do what it says here-- L1 plus L2. 14 00:00:46,120 --> 00:00:50,421 So it's going to be the list [re, mi]-- uh, yeah, mi. 15 00:00:53,410 --> 00:00:57,250 Now, extend() is going to mutate the list. 16 00:00:57,250 --> 00:01:03,040 So that means L3 is going to be extended by whatever L4 is. 17 00:01:03,040 --> 00:01:05,704 So L3 is going to be-- OK, what did it have originally? 18 00:01:05,704 --> 00:01:08,292 It had do. 19 00:01:08,292 --> 00:01:09,750 And then, it's going to be extended 20 00:01:09,750 --> 00:01:16,050 by all of the elements inside L4, which is re, mi, like that. 21 00:01:16,050 --> 00:01:20,030 And once I've mutated it, the old version of L3 22 00:01:20,030 --> 00:01:21,210 is gone, right? 23 00:01:21,210 --> 00:01:25,350 This is the L3 down here that I'm going to work with. 24 00:01:25,350 --> 00:01:28,380 L3.sort() is going to sort alphabetically. 25 00:01:28,380 --> 00:01:30,310 So that's [do, mi, re]. 26 00:01:34,090 --> 00:01:35,640 Yep. 27 00:01:35,640 --> 00:01:37,740 And sort() also mutates the list. 28 00:01:37,740 --> 00:01:39,690 So the old version of the list I have is gone. 29 00:01:44,420 --> 00:01:47,250 del is going to also mutate the list. 30 00:01:47,250 --> 00:01:52,440 So it's going to look in L3, look at index 0, 31 00:01:52,440 --> 00:01:54,620 and it's going to delete that-- it's 32 00:01:54,620 --> 00:01:57,380 going to delete that element. 33 00:01:57,380 --> 00:01:59,240 So it's going to mutate L3. 34 00:01:59,240 --> 00:02:03,140 And it's going to be [mi, re], OK? 35 00:02:03,140 --> 00:02:04,760 And once again, I've mutated the list. 36 00:02:04,760 --> 00:02:08,000 So the old version's gone. 37 00:02:08,000 --> 00:02:12,500 And lastly-- this is a tricky part-- I'm going to append, 38 00:02:12,500 --> 00:02:20,350 to my current L3, which looks like this, another list. 39 00:02:20,350 --> 00:02:24,050 So to L3, I'm appending another list. 40 00:02:24,050 --> 00:02:29,758 So this is going to be the list [fa, la], OK? 41 00:02:33,240 --> 00:02:36,380 So [mi, re], and then the list [fa, la] is the answer, 42 00:02:36,380 --> 00:02:42,445 which is red-- no, sorry, blue. 43 00:02:42,445 --> 00:02:44,160 Good, you had me scared. 44 00:02:44,160 --> 00:02:46,120 OK. 45 00:02:46,120 --> 00:02:48,334 Perfect. 46 00:02:48,334 --> 00:02:49,750 So if you didn't get this, I would 47 00:02:49,750 --> 00:02:53,063 suggest you go through the Python tutor 48 00:02:53,063 --> 00:02:55,354 or you just trace it out by hand, just like I just did. 49 00:02:58,130 --> 00:03:01,850 And hopefully it'll be apparent, the more 50 00:03:01,850 --> 00:03:04,960 exercises you do with lists, what exactly is going on. 51 00:03:04,960 --> 00:03:06,510 OK.