This video is titled Lists. I'm going to go over in the software editor, some of the things that I already went over in the lesson. But I think when we get into some of the more complex subjects with encoding, it's important to be redundant about these things, particularly with lists, since there's so many things that you can do with lists. I just wanted to point out with this video their operation. Just run through some things that I was talking about within the lesson, and then we're going to, of course build on these things throughout the rest of the course. So I'll run through this fairly quickly, but you'll have the code yourself to go through, and experiment with some of these things, which is really the best way for understanding them. These lists are created with the equals, values, in between brackets separated by commas and they're organized in the same way that we talked about tuples, indexically from left to right, starting with zero, and separated by commas. They can hold all data types, mixed data types, or just numbers, which we'll tend to use a lot, and I can also define an empty list. The reasons will become clearer when we get to things like iteration, why I would want to define an empty list. I can simply add lists together, which is just going to increase the size of the list by putting those together. We'll print that out, and see what that looks like, and then I can also nest lists in lists. I can have lists within lists within lists. As I mentioned earlier, that's what we do when we save a list of points. A list of points is essentially a list of lists, or a list of tuples. So let's run these first two, and we'll see what they output. So this is list 1 and list 2 just added together, and then this list 5 is list 1 and list 2 nested within. My points are already in a list. I don't need to put them in parenthesis, so that's feeding a list. So if I run this, it's creating that circle, and now I could leave it like that, or I could rescale it so it fits in here, depending on what design I want to do. But we can use a function which we've used before, which is scale object, and I'm saving that curve in a variable called curve. Then I'm scaling it around the centroid to half its size uniformly. I'm not creating a copy of it, I want to scale the original object. Let's run that again. Okay. I can undo that. Let's get rid of this for a sec. We can turn our labeling off. We don't need that anymore. Shift control C. I could manipulate a rectangle. With this it'll also work with any closed polyline 4-sided. So I could just draw as long as I close it. Actually, it doesn't matter which direction I draw in. Let me just do a couple more here. So I'm drawing a tower of connected polygons, and then I can run the code on each one of those polygons separately. So you can see from this you can start to imagine the lists. It might be tough to read at first, but you can see that those lists are within their own brackets, within a bigger set of brackets. So I can tell that there are two lists within a larger list. Let's do Shift control U to uncomment that. If we extract data from those which is in the same way that I do with tuples, it gives the name here and then the index number of the value that I want to extract from list 01. Then if I have nested lists, I need to decide on the first number. Sorry, the first number is the index number of the list. So in this case, actually, this is, since our counting starts at zero, this is list 1 and then I'm extracting the index number 2 out of that list 1, which should be seven. So this should print out, let's see, three from list 1 should be pair. So I should get pair and seven out of that, which I do. So pair and seven. We can overwrite lists. So we Shift control U. We can overwrite lists. So I can overwrite list 1 by just re-assigning it. Unlike tuples, I can overwrite just one indexical value within that list. So it's just going to replace. Let's run that. So down here at the bottom we'll see list 01 prints out. So that's after I've overwritten it. Then I'm overwriting index value 1, which is eight with 75. Finding the length of the list. So very handy Python function len, L-E-N. If I put in parentheses the list name, it's going to tell me the length of it. So it's saying list length is three. So it's telling me it's holding three items in it and this is going to be an issue. We'll see also when we get to iteration that since my counting starts at zero, the last indexical item in a list that's 23 is index 2 slot which is going to be one less than the list length. Since my counting starts at zero. That's something that we're going to have to get used to in iteration. Lists are mutable. So actually let me turn some of this off. Let's go from here up and Shift Control C, comment that out, so I'm not printing everything out. Okay. So lists are mutable. Unlike tuples, I can do things, a lot of different things to them. If you look at the Python site, python.org, and you lookup lists, you'll see that there are innumerable ways of manipulating and accessing the data in a list. What I'm showing you here is really the ones that we're going to use within the course. You can go look at that. You'll see that there's actually quite a few other things that you can do. But I'm showing most useful ones for us within the course and the ones that you're going to want to understand and work with. So adding values to the end of the list, this is an important one that we'll use a lot. So uncomment that. So using append. Now, this is the first instance too that we're seeing something called a method. A method, works a little differently than a function in that you can see it's preceded by the name of the list or the variable name, which is then followed by a dot and then I am writing the method append. Then in the parentheses after append, I'm giving a value which I want to append. So this is the value I'm going to append to the end of list 01. So let's run that. So it's adding the value 50 to the end of list 01. So append always adds to the end of a list. I can also add values to an empty list. So up here I've defined list 03 as an empty list by giving a setting equal to closed brackets. Let's uncomment that. So I'm going to add the value of 20 to list 03 and then we're going to print that out. So at first it prints out that it's an empty list and then it shows me that it's holding 20. So what if I wanted to add a bunch of values to that list? Let's uncomment that. I'm trying to add three values to that list and it's throwing an error. So it's telling me that the method append takes one argument and I'm giving it three. So I'm giving it two more arguments than it needs. So what it's telling me is that I can't do this. I can't give it three values. So I have to give it one at a time. Now, I could, if I put these in parentheses, it is on parentheses which makes those three values a tuple. If I run this again, then I don't get an error and it's showing me in list03 that it now contains the tuple. So I can add tuples because it sees a tuple as one item. I could do the same thing if I wrote this as another list between brackets, it would still work and it actually shows me that it's holding a list now because it has those brackets around it. A reversing; so I can reverse the items in a list by using the method reverse. I don't need anything between the parentheses, although I still need to write them to get the method to work, reversing items in list01 and we'll see what that is first, and then we'll see what it's after. Let's turn some things off here and I'll need to print the length, comment these out, "Control and Shift C". It's showing me a list01 here and then it's showing me it's reversing it. We can sort. So let's sort list01. Let me leave that reassignment on. Still I want to print these out. So we're sorting list01. So sorting, if I have a numerical assignments within the list and I choose sort, it's going to put them in a numerical order from lowest to highest. Oftentimes, we'll use sort and reverse in succession if I wanted to flip this order of numbers from highest to lowest for some reason. If we reassign list01 back to its original, what I originally had it at, so now it's a mix of things. I have numbers, I have Boolean and I have a couple of strings. If I sort that, what am I going to get? If I'm sorting a list of mixed data types, it's going to put them in a specific order. I don't have all data types in here, but this gives you some idea of what it's going to do. It puts my Booleans first, it then puts numbers, both integers and floats. It'll put in order and then it puts strings in alphabetical order. I can insert something in a list, so this is a variation on append. So if I wanted to insert, let's say, a number 365 into a particular index, index1, in list01, I could do that. So it's inserting 365 into the list01 and then it's moving everything over to the right. That's after that, they'd become one more index equal value. Deleting; I can delete an item from a list by just using the function delete, then the list name, and then the index number in brackets. So this is going to delete index number 3, which is going to be zero, one, two, so it should be 10.5 that it deletes, which it does, see down here. Then lastly, popping, which is like deleting. One difference is I can set it equal to something. So it's really like extracting. So it deletes from the list, pops something out of a list. So I give the index number, the list name and so the pop is a method period, then pop and then the index number of the item I want to pop out, so it should pop out true out of list01. Then I can set that equal to a new variable if I wanted to save that thing that I'm popping out, and that should print out down here. Which it does and it also shows me that it's popped it out of that list. So lot of things you can do with lists, tuples, and in the next series of lessons, we're going to go through how we start to apply these in collecting data, doing things with data in the code using lists and tuples. We'll go through that and then I'll lead us up to our next assignment.