1 00:00:00,610 --> 00:00:02,190 - For this self check exercise, 2 00:00:02,190 --> 00:00:04,590 I'd like you to start out by creating a list 3 00:00:04,590 --> 00:00:07,700 called rainbow containing green, orange and violet 4 00:00:07,700 --> 00:00:10,800 and then perform the following four steps 5 00:00:10,800 --> 00:00:14,110 and after each of these steps, display the current 6 00:00:14,110 --> 00:00:17,150 set of values within the list so first, 7 00:00:17,150 --> 00:00:20,050 we want you to figure out the index of violet 8 00:00:20,050 --> 00:00:25,050 then use that to insert red before violet in the list. 9 00:00:25,610 --> 00:00:28,760 Then, we want you to append yellow to the end of the list. 10 00:00:28,760 --> 00:00:31,150 We want you to reverse the list elements 11 00:00:31,150 --> 00:00:33,849 and finally, we want you to remove the element 12 00:00:33,849 --> 00:00:37,500 that contains orange so go ahead and pause the video 13 00:00:37,500 --> 00:00:39,670 and give those exercises a shot, 14 00:00:39,670 --> 00:00:42,033 then you can come back here to see the answers. 15 00:00:46,330 --> 00:00:48,641 Okay, so as you can see, I've already gone ahead 16 00:00:48,641 --> 00:00:52,720 and created the list so let me execute that 17 00:00:52,720 --> 00:00:55,670 to physically create it within this notebook. 18 00:00:55,670 --> 00:00:58,900 By the way, that's a common error when you're executing 19 00:00:58,900 --> 00:01:02,370 code in a notebook where you perhaps execute a cell 20 00:01:02,370 --> 00:01:05,020 after a previous cell and the 21 00:01:05,020 --> 00:01:07,660 previous cell has not been executed yet 22 00:01:07,660 --> 00:01:11,290 so something may need to be defined that is not yet defined 23 00:01:11,290 --> 00:01:14,750 and you could wind up with some errors if you're not careful 24 00:01:14,750 --> 00:01:17,996 so we intend for our notebooks to be executed 25 00:01:17,996 --> 00:01:22,040 from top to bottom in order but of course 26 00:01:22,040 --> 00:01:24,960 when you're working in the context of a notebook, 27 00:01:24,960 --> 00:01:27,670 you actually can execute cells in any order 28 00:01:27,670 --> 00:01:31,030 by just clicking in a cell and telling it to execute. 29 00:01:31,030 --> 00:01:35,410 So just be careful when you're working with our notebooks. 30 00:01:35,410 --> 00:01:37,790 So, for our first part there in part A, 31 00:01:37,790 --> 00:01:41,970 we want to insert the string red before the string violet 32 00:01:41,970 --> 00:01:45,239 so the way we did that was to first use the index method 33 00:01:45,239 --> 00:01:49,857 to find violet's index number within the rainbow list 34 00:01:49,857 --> 00:01:53,130 and here we can see it's at index two so basically, 35 00:01:53,130 --> 00:01:56,614 we're saying let's insert at index two the string red 36 00:01:56,614 --> 00:02:01,290 and let's then go ahead and display the contents of rainbow 37 00:02:01,290 --> 00:02:04,830 and indeed we did insert in front of violet. 38 00:02:04,830 --> 00:02:08,070 Next, we wanted to append yellow to the end of the list 39 00:02:08,070 --> 00:02:10,510 so we have the append method for that purpose 40 00:02:10,510 --> 00:02:13,490 and of course we can evaluate rainbow once again 41 00:02:13,490 --> 00:02:16,126 to confirm that yellow was appended. 42 00:02:16,126 --> 00:02:17,710 To reverse the elements, 43 00:02:17,710 --> 00:02:21,320 we can simply call the reverse method, so let's do that 44 00:02:21,320 --> 00:02:24,720 and let's go ahead in the next cell here 45 00:02:24,720 --> 00:02:27,890 and display the elements in reverse order. 46 00:02:27,890 --> 00:02:30,514 And then finally, we wanted to remove the element 47 00:02:30,514 --> 00:02:34,760 containing orange and we can do that with the remove method 48 00:02:34,760 --> 00:02:38,881 and the last evaluation of the list shows you that indeed, 49 00:02:38,881 --> 00:02:42,070 the orange object has been removed. 50 00:02:42,070 --> 00:02:44,520 The orange string has been removed from the list.