1 00:00:00,890 --> 00:00:02,700 - [Instructor] In this video, we're going to start 2 00:00:02,700 --> 00:00:05,690 filling in a lot of the missing pieces 3 00:00:05,690 --> 00:00:09,000 about the list data structure in Python. 4 00:00:09,000 --> 00:00:11,580 Now, most commonly, lists are used 5 00:00:11,580 --> 00:00:14,030 to store homogeneous data. 6 00:00:14,030 --> 00:00:17,080 That means all data of the same type. 7 00:00:17,080 --> 00:00:20,410 So for example, here we're creating a list called c, 8 00:00:20,410 --> 00:00:22,970 and we've got a bunch of whole number values, 9 00:00:22,970 --> 00:00:26,820 all of those are considered to be integers in Python. 10 00:00:26,820 --> 00:00:28,880 Now there's no requirement in Python 11 00:00:28,880 --> 00:00:31,580 that all of the elements must be of the same type, 12 00:00:31,580 --> 00:00:35,180 so it is okay to store heterogeneous data 13 00:00:35,180 --> 00:00:36,980 in a list if you'd like. 14 00:00:36,980 --> 00:00:39,970 So for instance, I could have a combination of strings 15 00:00:39,970 --> 00:00:41,980 and integers and floating point numbers 16 00:00:41,980 --> 00:00:44,070 and any other type that you might 17 00:00:44,070 --> 00:00:46,440 be able to think of as well. 18 00:00:46,440 --> 00:00:48,900 Now of course, once we define a list, 19 00:00:48,900 --> 00:00:52,720 which again is done with a set of square brackets in Python 20 00:00:52,720 --> 00:00:55,470 we can evaluate that list to see 21 00:00:55,470 --> 00:00:57,030 what its contents look like 22 00:00:57,030 --> 00:00:59,590 in a string-based representation. 23 00:00:59,590 --> 00:01:02,310 So this is the output format for a list 24 00:01:02,310 --> 00:01:05,400 that's built into Python itself. 25 00:01:05,400 --> 00:01:08,890 Now one of the new things that we want to take a look at 26 00:01:08,890 --> 00:01:12,640 in this video is accessing individual 27 00:01:12,640 --> 00:01:14,580 list elements directly. 28 00:01:14,580 --> 00:01:17,170 So first I just want to show a diagram 29 00:01:17,170 --> 00:01:19,390 of the list that we just created. 30 00:01:19,390 --> 00:01:22,870 As in most C-based programming languages, 31 00:01:22,870 --> 00:01:26,830 indexing or accessing of the individual elements 32 00:01:26,830 --> 00:01:31,530 within a list is done from index number zero. 33 00:01:31,530 --> 00:01:35,200 So the value 45, or minus 45, excuse me, 34 00:01:35,200 --> 00:01:38,750 is at index position zero within the list c, 35 00:01:38,750 --> 00:01:41,860 and this is the actual syntax that you would use 36 00:01:41,860 --> 00:01:46,860 to name the location in memory where minus 45 is stored 37 00:01:47,170 --> 00:01:50,550 so that you can get that value and use it, 38 00:01:50,550 --> 00:01:55,550 or so that you can assign a new value to that element 39 00:01:55,560 --> 00:01:57,490 of the list if you would like. 40 00:01:57,490 --> 00:02:00,940 So you can see here, the names of the five elements 41 00:02:00,940 --> 00:02:03,040 of the list that we just created 42 00:02:03,040 --> 00:02:06,930 are c sub zero through c sub four. 43 00:02:06,930 --> 00:02:09,780 So with that said, let's go back over 44 00:02:09,780 --> 00:02:12,740 to our interactive iPython session, 45 00:02:12,740 --> 00:02:15,330 and let's just display the values 46 00:02:15,330 --> 00:02:17,900 of a couple of the elements in our list. 47 00:02:17,900 --> 00:02:21,340 So c sub zero is indeed minus 45, 48 00:02:21,340 --> 00:02:26,340 and c sub four is indeed 1543, the last element of the list. 49 00:02:28,660 --> 00:02:31,640 Now we talked previously about the fact 50 00:02:31,640 --> 00:02:34,790 that lists know their own length. 51 00:02:34,790 --> 00:02:39,501 So let's go ahead and check the length of the list c, 52 00:02:39,501 --> 00:02:41,730 and we can see that indeed it has five elements, 53 00:02:41,730 --> 00:02:43,760 and you can confirm that by counting 54 00:02:43,760 --> 00:02:47,280 the elements back in the original list up above. 55 00:02:47,280 --> 00:02:48,790 I should mention, by the way, 56 00:02:48,790 --> 00:02:52,080 that unlike many C-based programming languages, 57 00:02:52,080 --> 00:02:56,710 Python does not have a data structure called an array 58 00:02:56,710 --> 00:02:59,662 built into the language itself. 59 00:02:59,662 --> 00:03:01,790 List is the closest thing to an array 60 00:03:01,790 --> 00:03:04,250 that we have in Python. 61 00:03:04,250 --> 00:03:07,120 Arrays in most other C-based programming languages 62 00:03:07,120 --> 00:03:09,390 are fixed-length entities, 63 00:03:09,390 --> 00:03:12,720 whereas Python lists are dynamically 64 00:03:12,720 --> 00:03:14,700 resizable and changeable, 65 00:03:14,700 --> 00:03:17,900 so they're a lot more flexible than arrays 66 00:03:17,900 --> 00:03:19,890 in most programming languages. 67 00:03:19,890 --> 00:03:24,890 When we do talk about the concept of arrays in these videos 68 00:03:25,120 --> 00:03:27,770 we'll do so a couple of lessons from now 69 00:03:27,770 --> 00:03:32,770 when we introduce the NumPy Numeric Python library, 70 00:03:32,830 --> 00:03:35,671 which is the most popular library 71 00:03:35,671 --> 00:03:37,703 for manipulating array data structures, 72 00:03:39,653 --> 00:03:41,430 performance-wise, in Python. 73 00:03:41,430 --> 00:03:43,470 And by the way, when we get to that point, 74 00:03:43,470 --> 00:03:45,880 we'll talk about some of the reasons 75 00:03:45,880 --> 00:03:50,880 why numerical Python arrays are more efficient than lists. 76 00:03:51,480 --> 00:03:53,810 We'll even do some timing comparisons 77 00:03:53,810 --> 00:03:57,130 on some similar operations. 78 00:03:57,130 --> 00:03:59,410 Now one of the things that's really interesting 79 00:03:59,410 --> 00:04:03,240 about lists in Python versus arrays 80 00:04:03,240 --> 00:04:05,330 in some other programming languages 81 00:04:05,330 --> 00:04:10,300 is the fact that in addition to positive index numbers, 82 00:04:10,300 --> 00:04:13,020 which by the way must be integer values, 83 00:04:13,020 --> 00:04:16,150 you can also use negative index numbers 84 00:04:16,150 --> 00:04:20,090 to access the elements from the end of a list. 85 00:04:20,090 --> 00:04:23,350 So let's go ahead and take a look at a diagram 86 00:04:23,350 --> 00:04:26,840 that adds in the negative index names 87 00:04:26,840 --> 00:04:30,183 of the elements in our five element list called c. 88 00:04:31,318 --> 00:04:33,950 Now as you can see here, c sub minus one 89 00:04:33,950 --> 00:04:37,000 actually represents the last element of the list. 90 00:04:37,000 --> 00:04:39,900 c sub minus two is the second to last element, 91 00:04:39,900 --> 00:04:41,890 minus three is the third to last element, 92 00:04:41,890 --> 00:04:44,360 all the way down to minus five, 93 00:04:44,360 --> 00:04:46,270 which is actually the first element. 94 00:04:46,270 --> 00:04:49,050 So basically you can figure out the corresponding 95 00:04:49,050 --> 00:04:54,050 positive index by adding the list's length 96 00:04:54,530 --> 00:04:57,570 to the negative indices that you see here. 97 00:04:57,570 --> 00:05:02,370 So if I add five to minus one, I get four, 98 00:05:02,370 --> 00:05:05,390 which is the last element of the list. 99 00:05:05,390 --> 00:05:07,970 If I add five to minus two, I get three. 100 00:05:07,970 --> 00:05:10,290 If I add five to minus three, I get two, 101 00:05:10,290 --> 00:05:12,922 et cetera all the way back to, 102 00:05:12,922 --> 00:05:15,550 if I added five to minus five, I get c sub zero, 103 00:05:15,550 --> 00:05:19,070 which of course is the first element within the list. 104 00:05:19,070 --> 00:05:21,660 So with that said, let's switch back over 105 00:05:21,660 --> 00:05:26,145 to the interactive iPython session here, 106 00:05:26,145 --> 00:05:28,790 and let's try accessing a couple of elements 107 00:05:28,790 --> 00:05:30,910 using negative indices. 108 00:05:30,910 --> 00:05:32,950 So if I say c sub minus one, 109 00:05:32,950 --> 00:05:37,950 that says I want the first element from the end of the list, 110 00:05:38,840 --> 00:05:42,800 and that first element from the end of the list is 1543. 111 00:05:42,800 --> 00:05:45,670 So indeed, we do get 1543 there. 112 00:05:45,670 --> 00:05:48,343 And if I say c sub minus five, 113 00:05:49,922 --> 00:05:51,890 we're saying we want to go backwards 114 00:05:51,890 --> 00:05:54,710 five elements from the end of the list. 115 00:05:54,710 --> 00:05:56,850 So if I go from the end of the list backwards, 116 00:05:56,850 --> 00:05:59,410 one, two, three, four, five, 117 00:05:59,410 --> 00:06:03,110 I'm saying I want actually the first element of the list 118 00:06:03,110 --> 00:06:05,120 in that particular case. 119 00:06:05,120 --> 00:06:09,463 Now, the index values that you use 120 00:06:09,463 --> 00:06:14,463 must be either integer values or integer expressions. 121 00:06:14,700 --> 00:06:19,109 So for example, if I go and I define a variable a 122 00:06:19,109 --> 00:06:19,942 and I give it the value one, 123 00:06:19,942 --> 00:06:21,750 and let's define another variable b 124 00:06:21,750 --> 00:06:23,420 and give the the value two, 125 00:06:23,420 --> 00:06:27,430 I can write an expression like c sub a plus b, 126 00:06:27,430 --> 00:06:30,140 and of course a plus b will be evaluated first 127 00:06:30,140 --> 00:06:32,290 to give me the value three. 128 00:06:32,290 --> 00:06:35,350 And going back and looking at our original list here, 129 00:06:35,350 --> 00:06:37,750 zero, one, two, three, 130 00:06:37,750 --> 00:06:42,360 the element with the value 72 is what we'll be accessing 131 00:06:42,360 --> 00:06:44,963 when we evaluate that expression. 132 00:06:46,000 --> 00:06:49,770 Now I've mentioned a couple of times that lists are mutable 133 00:06:49,770 --> 00:06:53,090 meaning that you can change their contents. 134 00:06:53,090 --> 00:06:55,210 Well, one way to change the contents 135 00:06:55,210 --> 00:06:59,110 is to assign a new value to an existing element. 136 00:06:59,110 --> 00:07:03,500 So for instance, if I write an expression like c sub four 137 00:07:03,500 --> 00:07:07,620 gets the value 17, now when I display 138 00:07:07,620 --> 00:07:09,330 the contents of the list, 139 00:07:09,330 --> 00:07:13,597 I can see that 17 has replaced the old value 1543 140 00:07:14,780 --> 00:07:17,600 in the last element of our list. 141 00:07:17,600 --> 00:07:20,610 So that's one way in which lists are mutable. 142 00:07:20,610 --> 00:07:25,080 We'll talk about dynamically modifying the size of a list 143 00:07:25,080 --> 00:07:27,250 in a few moments as well. 144 00:07:27,250 --> 00:07:29,860 Now some of the sequences that you're going to wind up 145 00:07:29,860 --> 00:07:32,730 manipulating in Python are immutable, 146 00:07:32,730 --> 00:07:34,970 and we've actually already dealt 147 00:07:34,970 --> 00:07:37,000 with two different sequence types 148 00:07:37,000 --> 00:07:41,510 that are immutable in Python, strings and tuples. 149 00:07:41,510 --> 00:07:44,080 So let's talk about a string for just a moment here. 150 00:07:44,080 --> 00:07:48,570 Let's say we create a string, and we give it the value hello 151 00:07:48,570 --> 00:07:53,570 and by the way all sequences can be accessed 152 00:07:53,610 --> 00:07:56,740 element-by-element using similar techniques 153 00:07:56,740 --> 00:07:59,540 to what we've shown you here for lists. 154 00:07:59,540 --> 00:08:01,770 So for example, I can go and say, 155 00:08:01,770 --> 00:08:06,483 give me the character at position zero in that string. 156 00:08:07,407 --> 00:08:09,380 In Python, we don't have a separate character type, 157 00:08:09,380 --> 00:08:12,400 so what we actually get out of this is a string 158 00:08:12,400 --> 00:08:17,400 representing that one character within the string. 159 00:08:17,426 --> 00:08:19,840 So s sub zero is the letter h. 160 00:08:19,840 --> 00:08:23,530 Now, like I said, strings are immutable, 161 00:08:23,530 --> 00:08:26,850 so if you attempt to place a new character 162 00:08:26,850 --> 00:08:30,030 into that position, let's say we wanted to replace 163 00:08:30,030 --> 00:08:32,580 the lowercase h with an uppercase H, 164 00:08:32,580 --> 00:08:35,340 what you're going to get as a result of that 165 00:08:35,340 --> 00:08:38,380 is an exception at runtime here. 166 00:08:38,380 --> 00:08:41,500 So in this case you see a type error. 167 00:08:41,500 --> 00:08:44,790 It's a type error because the string type str 168 00:08:44,790 --> 00:08:47,050 doesn't support assignment 169 00:08:47,050 --> 00:08:49,423 to the elements within the string. 170 00:08:50,950 --> 00:08:54,780 So previously we showed you that a list knows its own length 171 00:08:54,780 --> 00:08:57,270 and that we're able to calculate that length 172 00:08:57,270 --> 00:09:01,880 by passing the list to the built-in function named L-E-N, 173 00:09:01,880 --> 00:09:04,680 len in the Python language. 174 00:09:04,680 --> 00:09:08,028 Now, because lists know their own length, 175 00:09:08,028 --> 00:09:10,740 they do check when you specify an index 176 00:09:10,740 --> 00:09:14,330 to see whether that index is in range, as you might expect. 177 00:09:14,330 --> 00:09:17,590 So let's go ahead and try to access an element 178 00:09:17,590 --> 00:09:20,220 that's not part of our list c, 179 00:09:20,220 --> 00:09:23,900 and you can see that we get an index error in this case 180 00:09:23,900 --> 00:09:27,580 indicating that the list index is out of range. 181 00:09:27,580 --> 00:09:30,880 Of course, each of the elements within the list 182 00:09:30,880 --> 00:09:34,180 is effectively a variable unto itself. 183 00:09:34,180 --> 00:09:36,570 So you can also do things like use 184 00:09:36,570 --> 00:09:39,280 the different list elements in expressions. 185 00:09:39,280 --> 00:09:42,870 So if we do c sub zero plus c sub one 186 00:09:42,870 --> 00:09:46,740 plus, whoops, plus c sub two for example, 187 00:09:46,740 --> 00:09:48,570 that will simply add together 188 00:09:49,442 --> 00:09:51,710 the first three elements of the list. 189 00:09:51,710 --> 00:09:53,580 Now we already demonstrated up above 190 00:09:53,580 --> 00:09:56,870 that lists are modifiable, 191 00:09:56,870 --> 00:10:00,900 and you can actually add new items to a list 192 00:10:00,900 --> 00:10:02,370 a couple of different ways, 193 00:10:02,370 --> 00:10:05,870 one of which is using the plus equals operator 194 00:10:05,870 --> 00:10:08,000 that we've demonstrated previously. 195 00:10:08,000 --> 00:10:11,970 So let's say we have a variable called a_list 196 00:10:11,970 --> 00:10:15,010 and we initialize it with an empty set of square brackets, 197 00:10:15,010 --> 00:10:18,850 which means a list of no elements at least so far. 198 00:10:18,850 --> 00:10:23,010 Because lists are mutable, we can add items to the list, 199 00:10:23,010 --> 00:10:25,270 like I said, using that plus equals operator. 200 00:10:25,270 --> 00:10:30,000 So for example, if we wanted to add the numbers 201 00:10:30,000 --> 00:10:32,240 from one through five to the list, 202 00:10:32,240 --> 00:10:35,220 we could write a for loop, something like this, 203 00:10:35,220 --> 00:10:38,120 where we use the range function, 204 00:10:38,120 --> 00:10:40,410 and remember that range produces values 205 00:10:40,410 --> 00:10:42,560 from the starting value up to 206 00:10:42,560 --> 00:10:44,860 but not including the ending value. 207 00:10:44,860 --> 00:10:48,400 And for each of those, we can go ahead and say 208 00:10:49,256 --> 00:10:52,611 a_list plus equals and number, 209 00:10:52,611 --> 00:10:55,200 and that will now go ahead, I'm sorry. 210 00:10:55,200 --> 00:10:56,483 I typed that wrong. 211 00:10:58,077 --> 00:11:00,970 We can do plus equals with number in square brackets, 212 00:11:00,970 --> 00:11:05,690 which will add a list containing just the number 213 00:11:05,690 --> 00:11:09,030 to the end of the variable a_list. 214 00:11:09,030 --> 00:11:11,433 Now what that does is it concatenates 215 00:11:12,380 --> 00:11:15,740 this one element list that we are currently 216 00:11:15,740 --> 00:11:17,650 putting on the right side of the expression 217 00:11:17,650 --> 00:11:22,650 to the end of the elements currently stored in a_list. 218 00:11:22,970 --> 00:11:25,540 Now this is important, the plus equals operator's 219 00:11:25,540 --> 00:11:30,470 right-hand side must be something that is a sequence 220 00:11:30,470 --> 00:11:33,900 in order for the plus equals operator to work correctly. 221 00:11:33,900 --> 00:11:37,683 So it's a concatenation operator in this context. 222 00:11:39,121 --> 00:11:40,740 So let's go ahead and execute that for loop, 223 00:11:40,740 --> 00:11:43,870 and now we can evaluate a_list 224 00:11:43,870 --> 00:11:46,990 and see that we were able to place the values 225 00:11:46,990 --> 00:11:49,150 one through five into the list. 226 00:11:49,150 --> 00:11:51,840 So let's go back to this issue 227 00:11:51,840 --> 00:11:55,260 of the right-hand side of the plus equals operator. 228 00:11:55,260 --> 00:11:59,340 When the left side of this operator is a list, 229 00:11:59,340 --> 00:12:04,340 the right side must be some sort of iterable object, 230 00:12:04,680 --> 00:12:07,960 typically a sequence like a list or a tuple, 231 00:12:07,960 --> 00:12:09,637 or even a string. 232 00:12:09,637 --> 00:12:13,420 So for example, if I go and create a list called letters, 233 00:12:13,420 --> 00:12:14,943 which is currently empty, 234 00:12:15,837 --> 00:12:18,220 and then I say letters plus equals, 235 00:12:18,220 --> 00:12:20,539 and I give it the string. 236 00:12:20,539 --> 00:12:22,300 Actually, let's say Python here instead of hello, 237 00:12:22,300 --> 00:12:23,593 since I always do hello. 238 00:12:24,660 --> 00:12:26,240 So letters plus equals Python. 239 00:12:26,240 --> 00:12:29,950 Now, what you might think is going to happen here, sorry, 240 00:12:29,950 --> 00:12:32,540 is that the string object Python 241 00:12:32,540 --> 00:12:34,750 will be placed into that list. 242 00:12:34,750 --> 00:12:39,390 But in reality, what happens is each individual letter 243 00:12:39,390 --> 00:12:40,700 gets placed into the list. 244 00:12:40,700 --> 00:12:42,930 So now we have a list of strings 245 00:12:42,930 --> 00:12:46,540 where each string is one letter from the sequence 246 00:12:46,540 --> 00:12:50,920 that was on the right side of that plus equals operator. 247 00:12:50,920 --> 00:12:53,910 Now you might expect that if you can do plus equals, 248 00:12:53,910 --> 00:12:57,103 you can also do plus, and indeed you can. 249 00:12:58,566 --> 00:13:02,760 So the plus operator acts as a concatenation operator 250 00:13:02,760 --> 00:13:04,410 in the context of lists. 251 00:13:04,410 --> 00:13:07,680 So let's say we have a list with 10, 20, and 30, 252 00:13:07,680 --> 00:13:09,430 and let's say we have another list, 253 00:13:09,430 --> 00:13:14,430 and we'll make this one 40 and 50, just for argument's sake. 254 00:13:14,540 --> 00:13:18,640 Now if I go and create a concatenated list. 255 00:13:18,640 --> 00:13:21,423 Actually, let's call it that, concatenated_list. 256 00:13:23,290 --> 00:13:26,740 So we can say list1 plus list2. 257 00:13:26,740 --> 00:13:29,833 And if we then go and evaluate that, 258 00:13:31,730 --> 00:13:34,980 you can see that indeed the new list that was created 259 00:13:34,980 --> 00:13:37,900 contains all of the existing items. 260 00:13:37,900 --> 00:13:41,410 Now, because of the fact that we used the plus operator, 261 00:13:41,410 --> 00:13:46,410 neither list1 nor list2 got modified by snippet 26 here. 262 00:13:47,980 --> 00:13:50,670 If you're using the plus equals operator, 263 00:13:50,670 --> 00:13:52,760 as we did way back up here, 264 00:13:52,760 --> 00:13:56,680 we saw that that really did modify the empty list 265 00:13:56,680 --> 00:13:58,453 to add elements to the list. 266 00:13:59,600 --> 00:14:03,240 Now we can also use the for statement, 267 00:14:03,240 --> 00:14:07,866 along with the range function to access elements, 268 00:14:07,866 --> 00:14:09,220 (clears throat) excuse me, of a list, 269 00:14:09,220 --> 00:14:11,820 via their index numbers. 270 00:14:11,820 --> 00:14:15,930 So for instance, if I go ahead and write a for loop 271 00:14:15,930 --> 00:14:19,910 of this format, so we'll, for i in range, 272 00:14:19,910 --> 00:14:23,270 and then we use the len function to say, 273 00:14:23,270 --> 00:14:26,100 give us the length of the concatenated list. 274 00:14:26,100 --> 00:14:29,090 So let's talk about that before I continue. 275 00:14:29,090 --> 00:14:30,980 We already know that the len function 276 00:14:30,980 --> 00:14:34,300 is able to give us back the number of items in a list. 277 00:14:34,300 --> 00:14:36,720 The list we're talking about is concatenated_list, 278 00:14:36,720 --> 00:14:38,920 which has five elements, so the result 279 00:14:38,920 --> 00:14:41,520 of this expression is five. 280 00:14:41,520 --> 00:14:44,300 So for i in range five is really saying, 281 00:14:44,300 --> 00:14:47,460 give me the integer value zero through four, 282 00:14:47,460 --> 00:14:50,990 which are the indices of the list right up above 283 00:14:50,990 --> 00:14:53,320 that we just created. 284 00:14:53,320 --> 00:14:55,560 So now that we have that, 285 00:14:55,560 --> 00:14:58,070 we can go and do something like a print statement. 286 00:14:58,070 --> 00:15:00,680 Let's use a format string in this case. 287 00:15:00,680 --> 00:15:05,220 And we'll display the index number, 288 00:15:05,220 --> 00:15:09,300 followed by a colon, and in a second placeholder, 289 00:15:09,300 --> 00:15:13,310 let's go ahead and show the concatenated_list element 290 00:15:13,310 --> 00:15:17,130 at position i within that list. 291 00:15:17,130 --> 00:15:21,780 So close off our string and close the parenthesis. 292 00:15:21,780 --> 00:15:25,360 So now you can see the indices of the values, 293 00:15:25,360 --> 00:15:28,670 and the actual value at each index. 294 00:15:28,670 --> 00:15:32,150 So that's the same old indexed access 295 00:15:32,150 --> 00:15:34,663 that we did several times up above. 296 00:15:37,130 --> 00:15:39,060 One other thing I want to show you in this video 297 00:15:39,060 --> 00:15:43,260 with respect to lists is that, for convenience, 298 00:15:43,260 --> 00:15:48,080 you're able to compare the elements of multiple lists 299 00:15:48,080 --> 00:15:50,070 using the comparison operators 300 00:15:50,070 --> 00:15:52,040 that we showed you previously. 301 00:15:52,040 --> 00:15:55,140 So for example, if I go ahead and create a list, 302 00:15:55,140 --> 00:15:57,950 let's say, that has one, two, and three in it, 303 00:15:57,950 --> 00:16:00,060 and let's create a second list 304 00:16:00,060 --> 00:16:02,880 that also has one, two, and three in it. 305 00:16:02,880 --> 00:16:06,080 Woops, that's one, two, and three. 306 00:16:06,080 --> 00:16:08,420 And let's create a third list this time 307 00:16:08,420 --> 00:16:11,870 that has an extra element in it, one, two, three, four. 308 00:16:11,870 --> 00:16:14,440 Alright, so we have a few lists that we can work with. 309 00:16:14,440 --> 00:16:16,450 And let's say we want to know whether 310 00:16:16,450 --> 00:16:19,620 a couple of these lists are equal to one another or not. 311 00:16:19,620 --> 00:16:23,410 So for instance, if I do a double equals b, 312 00:16:23,410 --> 00:16:26,520 I'm comparing the list object that a refers to, 313 00:16:26,520 --> 00:16:28,940 with the list object that b refers to. 314 00:16:28,940 --> 00:16:32,970 The contents of these two lists are identical, 315 00:16:32,970 --> 00:16:36,550 and therefore, we get true as a result. 316 00:16:36,550 --> 00:16:41,550 Now, the list a is a subset of the list c, 317 00:16:41,810 --> 00:16:44,210 so they're not equal 'cause they don't have 318 00:16:44,210 --> 00:16:45,810 the same number of elements, 319 00:16:45,810 --> 00:16:48,010 and they don't have the same exact contents 320 00:16:48,010 --> 00:16:50,250 within the lists themselves. 321 00:16:50,250 --> 00:16:53,230 So in this case, you can see that we get false. 322 00:16:53,230 --> 00:16:56,620 Now interestingly, you can also use the less than, 323 00:16:56,620 --> 00:16:58,080 less than or equal, greater than, 324 00:16:58,080 --> 00:17:00,860 and greater than or equal operators also. 325 00:17:00,860 --> 00:17:03,930 So for instance, if I say a less than c, 326 00:17:03,930 --> 00:17:08,930 this is going to be true, because a is a subset of c. 327 00:17:09,650 --> 00:17:12,540 So indeed, we get true in that case. 328 00:17:12,540 --> 00:17:16,270 And, let's talk about c and b for a moment. 329 00:17:16,270 --> 00:17:18,860 c and b have some shared elements, 330 00:17:18,860 --> 00:17:21,060 just like a and c had shared elements. 331 00:17:21,060 --> 00:17:25,790 Let's do an expression like c greater than or equal to b. 332 00:17:25,790 --> 00:17:29,970 While c contains everything that b does and more, 333 00:17:29,970 --> 00:17:32,670 so as you can see, we get true 334 00:17:32,670 --> 00:17:34,610 as a result of that expression. 335 00:17:34,610 --> 00:17:37,470 So in this video we saw a whole bunch 336 00:17:37,470 --> 00:17:42,470 of different operations that you can perform on lists 337 00:17:42,784 --> 00:17:44,343 here in the context of Python.