Title of this video is Lists. So lists, lists are another form of our data structure in our data structure family. And as I mentioned in the lesson on Tuples, there's a very strong commonality between these two things that we'll see. And there's also a very strong difference between them. One difference is in how I write them. So tuples are defined between parenthesis, list or sign in very similar way but they are defined between brackets. A list is indexically organized exactly like a tuple is. So from left to right I have my slots defined by commas and the counting starts at 0,1,2,3,4, and so on. And then, in order to access the data that's in that particular slot, I need to write the list name followed by, the index number in brackets and that's going to allow me to access the data that's in that particular slot within the list. Just like tuples, we could think of them as this kind of endless filing cabinet. And in that filing cabinet I can put different data types can go within those drawers. And that filing cabinet is given a name which is the name of my list, which has to follow all the conventions that variables and tuples do. So, variable assignment we know about I can change the data within a list by overriding it just like I do with tuples, it works just the same. Now we start to see a difference. So I can change the data just in one slot of a list by setting the list name,you see in line 3 here the list name and the index slot that I want to change the data in. Set that equal to some new value. And so I'm allowed to overwrite just one slot of that list data. And so that leads us to think that maybe lists are a little different than tuples. And lists are what is called mutable, which means that there are a whole bunch of different ways that I can change the data in a list. And it's actually a fairly long list of things that I can do to lists and if you looked@python.org Just look up Lists. You'll be able to find a lot more than what we're going to use within this course. But, I'm going to show you the most common four, and really the four that we use most in this course along with another function that we'll use a lot. So, they are and we call these lists methods. They're append, sort, reverse and pop. And they need to be written in this way, in this manner where you start with the name of the list followed by a period and then writing the method followed by closed parentheses. So the first one we'll look at is append. And append is probably the most often used one and it allows us to add data to the end of a list, it appends it to the list. And we do that simply by writing what we want to append in those parentheses after the method. And it just adds data onto the end of that list. And we're going to see this actually use this quite a bit when we do things with iteration and looping. Where we're going through a loop over and over again and we can use a counter in the loop to add to a list automatically over and over again. It's very powerful form within coding. Sort takes the values in a list, and it reorganizes them in order. So if I had a list of numbers, it's going to reorganize them from lowest to highest If I happen to have other data types within that list. Let's say for example, I have numbers and I have some strings and I have some Booleans. It's going to organize them in this manner. It's going to put the Booleans first, then it's going to put the numbers and then it's going to put the strings in alphabetical order. You'll also notice here too, that I'm not putting anything within those parentheses, but I still need those parentheses. Because I don't actually need to put something in the parentheses because I'm just telling it to reorganize the list. I'm not adding anything to it. Reverse does just what it advertises. It just reverses the list. This is in index slot 1, index slot 0, that's 1, and that's 2, and that those index slots don't ever move around with the values. The values sort of change their index slots. The last method is pop, and written in this manner, without any value between the parentheses. All it does is it takes away the last element in the list. So it's taking away the 2 pops it out of the list. If I put a number in there in between the parentheses, it is going to remove that in that whatever data is in that index number. So it's removing the 5 because 5 is in the index slot 1. Now I can set my popping of data within a list equal to a variable, because that popping not only does it extract it but it's also returning it. Now If I don't set it equal to something, it's just going to be gone forever. But if I actually wanted to save that data, I need to set that method equal to some variable. And then if I print out what's in that variable, it's going to print out what's been popped out of that list. Sometimes I need to, and again, we're going to see this a lot in iteration, sometimes I need to define an empty list. I need to create a list that has nothing in it yet. In iteration, I need to do that before let's say I'd be before I loop through something, I need to have a list exists so I can add to it. And so we do that before we would do an append within a loop. So that's a really common thing to use in conjunction with a pen. There is a function that will use a lot in conjunction with lists. And we can also use it with tuples to, and it's called len. And what it returns is the length of the list. So the number of elements that are in the list. So here that starts at 0 1 2 3 4. But we see the number that it returns is 5 because I do have five elements in my list. This can be an interesting sticking point at least a certain ways that we have to write the code. It's because the number that's returned from len or the I should say the index value of the last element within a list is always one less than what len returns. Okay, and so that's going to be an important thing when we're, let's say looping through a list. Sometimes we go too far, because we haven't sort of subtracted that one from the length of the list that we're going through. And that'll doesn't make sense now, but it will make a lot of sense when we look at it within the software tutorials. You might be asking, can I put lists within lists or can I put tuples within in lists? And yes, you can. You can have nested lists within nested lists within nested lists. And we'll actually see this a lot when we create lists of points. Lists of points are essentially lists of tuples, which are lists of lists. And there is actually a way to access data within the list, don't worry about that right now. This might not make a lot of sense, but this first Val indexical value is referencing this first list within this list. And then the second indexical value is referencing we have 0 here and we have 1 here and we have 2 here. So it's referencing that 1. And so this is all hierarchically organized when I have lists within lists within lists, and that's why this would output the number 6. Tuples versus Lists. So why would I use if these lists are so amazing if I can do so many things with them? Why would I choose to use a tuples over a list? Well tuples are much more efficient in terms of their memory allocation. They're going to run much, much faster. I have 10s of thousands of points. That's going to really slow my machine down if I save them as lists. So the rule of thumb is, if you don't need to change that data within the list if you don't need to do anything to it, then save it as a tuple. And so your codes going to run a lot more efficiently. And so that's tuples and lists.