 Sounds good. That pops up. There we go. Well, hello, everyone, and welcome back to Sailor Academy's live series, Introduction to Python. This is unit two. Data structures, part one, lists and strings. If this is your first time joining us, feel free to go back and check out our course on Sailor.org, and you can catch up. All of the videos will be saved here on our YouTube channel so that you can catch up. If you're on the live stream, feel free to leave some, feel free to, well, the chat just disconnected, so that's great. Thanks, Google. You've been giving me a great morning. But feel free to leave a question in the chat. We'll get back to those questions. Again, if you are not up to date, you can come back, leave a comment, and they'll address any comments you have left for previous ones. But I think we didn't have any comments from last time. So before, without any more introduction from me, Dr. Eric Sack to lead you through the recap of unit four. Very good. Thank you. Thank you. So what I want to do is talk about pretty much I think really what the core of what Python is about and what it really, really has to offer. In some sense, I think what initially had set it aside, I mean, even historically as a language, people just thought through in sort of a minimal way, how to generalize the most basic structures for holding data. So you're used to the float data type. You're used to the int data type. You're used to the STR data type. And then the next, usually when you go through a classical kind of programming language, like maybe, you know, a C++ or something like that. The next step is to learn about something called arrays and arrays hold data of the same data type. So instead of just having one integer, you know, basically have a container that would contain, you know, 100 integers or 100 floats or 100 strings and characters, let's say. And so then what happened was people wanted to be able to program things more generally. And that meant, well, if you have an array, why do we have to be limited to the same data type? Why do we have to do that? It's good to have arrays because you compute with them and they're used all the time. And you've learned, hopefully maybe in some, you know, early math course, maybe you learned about something called a matrix. And a matrix is really, is a mathematical object that one programs using an array data structure in some computer languages. And the next step above that is to want to be able to throw anything into an array, you know, even the kitchen sink. It's not just to have one data type, but to have many, many different kinds of objects. And the path that, like a C to a C plus plus direction was to come up with this intermediate step before, and we're going to get to object oriented program. I'm going to speak a little bit about that today, a tiny bit, not as much as we get into in unit 10, but at least to go on that path that the intermediate step in between a class definition and an array definition was something called a structure. And so structures became very, you know, interesting, led to interesting ways of programming, because you could throw anything that you wanted into a structure as long as you defined it. And Python went a step further than that because in a structure, you have to go through the, you know, harassment basically of making sure that you've, you know, sort of dotted all your eyes and crossed all your T's and really developed the structure much in the same way that you would do what's called a class definition. And so Python did away with all that. Okay, we just want to have, you know, something that we're going to call an ordered, if I can spell that correctly, an ordered mutable collection of objects. And that's what a list is. It's a way to order data so that you can, so that you can refer to elements via their indices. You can sort of, you can use pointers basically to point out the objects that are contained within that list. So it kind of, it gives you the power of this, this kind of array notation that was preserved, you know, in terms of computer languages, but it allows you to do so much more. And that's what I want to talk about today. The reason that there, and so I'm going to throw these words out and we're going to use them a lot over the next three units and probably by the time we get to unit six, it'll be very, very clear. I don't want to focus so much on the concept of ordered versus unordered until I can get to data structures too or mutability versus immutability. It's important. And so when something is ordered, it basically means that you can, you can via, let's say a sequence, you can index each element within the list. And, you know, the, so the first element on the, since we start counting at zero and Python, the first element would be element zero, and then the second element would be element one. And so no matter what's in the list, and you can mix all kinds of data types together, they have some sense of ordering. You have a notion of what's first and what comes next on the list and what comes next on the list. So that's all there is to ordering. Mutability speaks to the ability to change values and you can, you can contrast this with other data types and I, you know, I think I'll avoid the issue of mutability probably to them. I may speak to it a little bit, but the mutable just means it's changeable, you know, you can change the values, let's say. And that's all there is to it. There are other, you know, data structures that are not ordered and there are other portions of data structures that are not mutable. And I think what I'd rather do is, is maybe hold that conversation off like I said, until we get to the second data structures and then it'll become immediately clear because you can compare and contrast. The only thing I want to say about ordered and mutability today is that, is that the objects are ordered, there's an ordering to them and you can change them if you want to. And that's kind of what you want, you know, from this list kind of a data structure, which generalizes the concept of an array. And I'm just, if you don't know what I'm saying, that's fine. But for those of you who may have programmed another languages, you've probably seen arrays. And this is the generalization. So that's all I want to say kind of introductory. That's really the flavor of what's going on in this module, in this unit. And so, let me come over to Replet for a second. So, and the syntax for building a list is relatively simple. You have to remember, and every language has its syntax. And this is just the way it is. You know, some languages use curly brackets. Real quick. Dr. Zach, you think you need to switch your screens? Oh, thank you. Thank you. Yes. Appreciate that. So, yeah, I'm forgetting to do that a lot lately. I don't know. Anyway, I'll take the one second to say, if you guys are curious what program this is, it's in the chat bar. I've added it. And if you're watching later, it'll be down in the description. Fantastic. Thank you. So we're over in Replet. And I'm just going to, I'm just going to build a list of stuff. I don't care what it is. The syntax is, well, let me put the number four and maybe the number five. And maybe I can put, you know, 5.6 and, you know, a string in as well. So you can see that I'm creating a list from integer data and float data and string data. And the syntax just means you, everything you want to put on the list, everything you want to put on the list. And that's what I'm going to do. And that's what I'm going to do between the left square bracket and the right square bracket. And the comma separates the values. And there really is an ordering. Like four is the, is the zero element. Five is the first element. 5.6 is the second element. And an ASDF is, it's not a very creative string, but, you know, it's still early. So I'll get better as we go on. And is the string element. It's in data structure. So the list is a built in Python data structure, just like float in. You're going to start somewhere. At some point we'll be, we'll be building up our own, you know, data structures or our own classes and so forth. But for now this is another one. And the print function again is very, very smart. It knows what to do with its own built in data types. If you use a different data type, if you build up your own class, print won't know what to do. You've got to kind of tell it what to do. But in this case you can, it'll know, it'll know to print out the elements that are on the list. Or I could print the type of a, okay. I could say print the type of this variable. And it'll tell me, Python will tell me this is a list. Okay. And notice it uses the word class next to it. So there's just a point where we can't necessarily avoid the concept of object oriented programming. Again, we get deeper into this in unit 10, but at least the cat's kind of out of the bag right now. We're revealing something here. That's incredibly important is that, is that if there's any data type in Python, it views that data type as what's called a class, which is the overarching category, you know, for that data type. So this class name is list. And whenever you have a class, you are afforded a number of options for computing with the data or the object that's contained in that class. So the class is list the object or the, I'm not going to use that word yet. The object is, is a, and then along with that, you have a series of methods that you can use that can operate on the elements of a. And so that's a nice thing to have. It's, it's, it's not like a is, has a lot more stuff than just four, five, five point six and a SDF at it. Okay. Along with that, you have, you have access to, that's interesting. You have access to a number of what are called methods to compute with. And that's kind of one of the themes of the, of this unit is, is not just, you know, the sort of one, one aspect is mastering the list, mastering how to access elements within a list. And that's where I'm going to start, but it's much, much, much, much bigger than that. The whole point is that Python is, is, is meant to give you as much flexibility, as much freedom to compute with in the simplest, most obvious kind of a way. So we'll get to the method calls in a moment for, for lists and so forth. But I just want to tell you that you, we want to think really big. We want to, we want to actually, even without getting into unit 10, we really want to consider just how powerful Python is when you, when, even when you just use their own built in data types. In this case, it's the list. And so then we could say something like this. I could say, well, now I need a way of accessing, accessing the elements within the list. Okay. And I might want to do it indirectly or directly. And so some, some data structures in Python are not ordered and that you have to use other methods to, you know, to, to access elements, but, but maybe what I want to do is I'm interested in, in the numbers four, five and five point six. And so the way that you access the elements is via an assumed implied, you know, index, you have to know how it works. So if I say print the number a zero, I print the number four because the index that's associated with this element four is zero. The index associated with the five is going to be the index, is going to be the index one. Okay. And so on and so forth. So, so the index that is associated with, is associated with the element is, is indispensable. And so often when, when I teach at the introductory level, it's for some reason, it takes students, some students, you know, a few seconds to, to wrap their head around the fact. That you can, once you create the list, the goal is to have access to the elements that are contained within the list. And so the index is, is, is an indispensable tool. And because the elements are ordered, the index is the, you know, method of choice for, for accessing elements that you create, you know, within the list. And, and that's how it works. So, and so this is, I just, I can't overemphasize. Like if I want to, you know, I could say, well, now that I've, I've referred to the number, you know, to the first element, which is five, you know, I can add, I can, I can operate on that element now. I can actually compute with that element. And so now I'm, I'm not just accessing element one, which is five. I'm performing a mathematical operation on it, which adds the number 56 to it. And so now I've actually performed a mathematical operation or, you know, you could create new variables using the assignment statement. I could say, well, take a two. And so a two in this case would be 5.6. And then maybe, you know, raise it to the fourth power or something like that, you know, and then maybe I'll say print the C. So the beauty of the indexing, and this is what students really have to get kind of early on. So I've taken a two 5.6 and raised it to the fourth power. Is that, is that these values. Okay. Can be opera operated on, you know, I mean, this is the whole reason why you create lists is because you're, you're planning on performing some type of operation on the elements. And therefore you need a way to access them. So there's the, the actual element in the list. And then there's the index, which refers to the elements on the list and nine times out of 10, what you're going to be doing when you create a list is, is you're going to be really in some sense programming with, with lists and sequenced data structures, ordered data structures. I'll get back to sequence in a second. Order data structures is to is, is really the gymnastics of indices, learning how to really manipulate the indices so that you can, you can, you know, just do interesting things with the, with the stuff that you put in the list. So that's one potential application. I'm going to take that a step further in a second. Yeah. And finally, if you wanted to, you know, you could set, you could set, you know, something like there is no A4. So in this case that the minimum index is zero one, two, and then three. So the maximum index is going to be a three. And so you're going to count from zero to three. But anyway, so let's make believe that you wanted to take the first element on the list. And, you know, you, you could set, you could either set it to a different value and set it to 567. If you wanted to. So now you can use the index to, to change values. And this is what the word, this is where the word mutable comes from is that you can change values, you know, within the, the elements within the array itself, if you, if you so choose. And, or you could, you can operate on them, you know, you could say a one is equal to a zero times 345 or something like that. And, and so now, now what can happen is, is that, is that you can, you can refer to elements, you can operate on them, and then you can, you can change other elements within the array. So, so a lot of programming oftentimes when one uses list and array types, type of types of data structures, you know, simply goes into determining how you're going to apply the indices to accomplish some kind of a calculation or some type of a manipulation, you know, or moving data around from here to there, maybe from one list to another list or something like that. Or, and so that's, as I said before, I think that the key concept when one starts out is to understand the difference between the element and the index that's referring to the element, and to really make that distinction, because as I said before, about 10 to 15% of students that I've taught, sometimes they mix that up for some reason. I don't quite understand it. Maybe it's the way it gets explained or what have you, but there is, there's the index is the key to accessing elements within, within the list. And one major application of indexing, if you were to do it this way, you don't, you don't have to, we'll see why in a second. But if you wanted to, if I've got this list with four elements and I could say for, let's say I, so we've talked about loops already. So here's one major application of, of loops. And again, I'm going to use a for loop just to, to make a point. So there is a built in function called length or LEN for length. It tells me the length of the list A. And it doesn't matter in some sense. What's in the list? We don't have to stop here, by the way, I just haven't taught you enough data structures to, to show you that you could pretty much throw anything that you want into the list. I've chosen the three data types that I've introduced so far, which is, you know, float string and integer, but you can throw anything that you want. And all the length function does is just create everything that has a comma next to it, basically, whatever it is. Like I said, if it's the kitchen sinker, what have you, it just, it counts those things between the commas. And that's, that's where the length comes from. It doesn't really care, you know, it doesn't care what, what you've put on list. So for instance, I can put a list on a list, right? I could put a new list and I could say, okay, well, here's a new list. And so in this case, the, this list, the length of it would be one, two, three, four. It has five elements. Okay. Whose indices range from zero to four. And that's exactly what the range function is going to do. It's going to give you an iter, it gives you the ability to iterate the loop from, since I've specified no other information that starts, it assumes you want to start counting at zero up to the length of A minus one in steps of one. So this I variable, just to review loops, is going to, if I print out, let's say the value of I, and then maybe what I do is, I'll just do it all on one line. Let's say like this, that if you do something like this, where within the loop, you're going to print out the index because, you know, just to, as a review of the for loop, we're going to count from zero to the length of A minus one. I'm going to print out the index and then I'm going to print out the element that's associated with that index. So this is a good exercise, a good introductory exercise to do. If you want to understand, you know, the difference between the index and accessing the element. So what I try and do in every line for, for I equals zero, A I, the Ith element, A zero is equal to four. When I is equal to one, A one is five. A two is equal to five point six. A three is equal to A SDF. And then A four is equal to this list. Okay. And so, so the whole point of this, this exercise is to recognize that, that Python, when you tell it to print an element that's on a list, if it has a way to do that, that's what it's going to do. So even though I have a list and you'll notice that list has its own indices associated with it. So, and I'll get into that in a second, because that's an important point. But, but the point is that you should be able to, if you're leaving this unit, look at a list like this and recognize that this, this list has, you know, five elements on it, whose indices range from zero to four. So, so you have to have a keen eye to know, to understand in some sense what an element is and what it could look like, because it could in fact be anything. And that's the beauty of Python is that, is that it's just, it's a very general, it doesn't really care what you put in as an element, it's a valid data type. It's a valid data structure. You could throw anything that you want in there. So again, that can be extremely powerful. Many times the way that lists are used, is they are used as a raise of numbers, right? Because you sometimes you want to compute with numbers within a matrix, let's say, or a vector or, again, I'm not going to go too far down on, on that tangent in this, in this development, but I'm just saying that, that is a very common way to use lists, but there are deeper ways of using them as well. And so I give you this example because there may be cases where you are interested in not only the value, but also the index of the value. Now, if you write other code where you don't really care about the index so much, you're just interested in the values associated with a given list, then you might say something for, you know, let's say a, and then I might say print val. So here this is, this is implicit, you know, the, there's the sort of the explicit version of this loop, which contains the index, but if I, let's say I didn't care about the index, well then what's going to happen is, and this, this word, I'm just again, kind of throwing at you, you know, it may have been brought up possibly, you know, somebody may have brought it up in, in some place in the, you know, kind of the relational operators, but it's dangerous to bring it up there because this is more of a set concept. And we haven't talked about sets yet. That's for data structures too, but the set, the concept of a set operator is that it's basically for any value that's in that set. And A is not a set, it's a list. So, you know, it's, it's a verse, in is a versatile keyword. So, but again, I don't want to go, I don't want to open up that can of worms. So anyway, but for that value in, in the list, it's just going to print the value out. So in, in one case, and then let me put something in here to break this up just to make it look nice and purdy, like that. And so in this case, what I'm doing, the second loop is just printing out the values on the list. Okay. So what's my point here? My point is that, is that I don't want to necessarily tell you, there's no good or bad way of programming something. And well, I take that back. There have been some bad programmers anyway, but what I'm trying to say is that, is that you as the expert have to decide, you know, how you would construct, let's say for example, a loop to compute something. There may be cases where you want access to the index and there may be cases where you don't. And in certain cases, if you don't care about the index, then that's fine. And, you know, I can give lots of examples where you may, or may not care about the index. Maybe I'll speak to that for about 30 seconds or so. So here maybe what I'll do, let's make believe I have a numerical list. Just again, something simple. This I always throw this out to, you know, introductory programmers, because I want programmers to learn how to program. And what do I mean by that? I mean that there are, there are just certain really basic algorithms that you should not leave an introductory programming course without knowing like the back of your hand. And it doesn't, it's not necessarily because we don't have other methods or functions or utilities that will be able to make certain computations. So for example, let's make believe I've got the numbers four, five, six and seven on my list. So it's not a very interesting list. It's got four elements that they're indexed from zero to three. And if you make believe that you wanted to sum these elements for some reason, I don't know, maybe you're playing on computing an average and averages you sum the elements and divide by the number of elements. There are plenty of, you know, there's actually a built-in sum function that will sum, that will do that. It'll sum those numbers, you know, I can just say something like this, I could say print, you know, the sum of A, for instance, like this. And, and, and so that'll, you know, that'll happen. And, you know, there's nothing up my, nothing up my sleeve when it comes to, you know, to doing that and just come back and do that. And then I'll read ourselves or this other stuff up here because I'm trying to make a point. Is that, you know, it's, it's not a big deal to sum these numbers. Okay. There's, it's a one-liner, it's a built-in, it's a built-in Python function where you can drop a list into that function and we'll get more into functions in the next unit, but, but the idea of a function is you drop something in and you get an answer out. In this case, I want to sum the elements on the list. And, and so it's easy to do that. So I'm not showing you what I'm going to show you. I'm not showing it to you because I don't want you to use the sum function. I do want you to use the sum function, but I'm telling you, like as a programmer, you need to know how the sum function works underneath the hood because that's instructional material that's so critical to you learning how to program. And the way programming works is part of the way it works is you build up a little toolbox of about 10 or 15 tricks and then you get better and better. You learn more and more algorithms after that, more sophisticated algorithms, you know, because the field is vast. But, but when you leave an, my position is when you leave an introductory programming course, there's a couple of things you need to know. Like you just, they're non-negotiable. Okay. They've got to be part of that toolbox of 10 or 15 tricks because what you do is you pull out those tricks, you know, as you begin to, to write real code. And that's what programming really is. It's not about just learning the syntax. I'm sure everybody coming in today knows what a for loop is but you use for loops to make computations. And so you, what you really have to learn how to do is you've got to have a, in some sense, a universal sort of English, possibly to math, to Python translation system in your brain that takes some problem specification in English and can convert that into an algorithm and code. That's really what programmers do because, you know, that's why programmers get hired is because, because you can do that because other people don't do that. You know, I mean, that's if, if they could do it, then they wouldn't hire you to do it. So that's the whole point is that, is that. So one really basic kind of an algorithm is just summing the values. So, so the way that you sum values is, is that you, you go into the loop and you cycle through the numerical values. And, and you just add them to a previous sum. So this is, sometimes I call this a running sum. Sometimes I call it. It's like, it's like the way you would keep score in a baseball game inning by inning, you start off with the runs for a team being equal to zero and each time you go into a new inning, as soon as you get that new value, you iterate to the next inning, then you add that value to the previous sum. And if you do that correctly throughout the whole game, then you have the correct number of runs at the end of the game. And that's what this loop is doing. So, so loops and lists are, are, are in my sense, they're inseparable. Okay. I really, I see them almost in some senses is, is being related to the same goal is usually the reason that you're, you're creating a list of stuff. And believe me, I, you know, I'm giving you a list of like four elements, but you can have like, you know, billions of elements on a list. And, and if you wanted to perform operations on that data, you would need some type of a loop to kind of cycle through and iterate through all the elements. So here's a, this is a simple example where if I, if I went through this loop and I, and each time I, I add a new value, print, let's say print the sum at this point. And notice, I want to show you something else too, is that this sum is a function, but it's a built-in function, but, but you can use it as a, you know, as a variable name. And if I do that, it's going to light up in this, you know, pinkish-purplish-violish color, because it's a word that Python recognizes. So I'm not using it as a function right now. I'm using it as a variable and I'm using the word sum to sort of those partial sums. And when you go ahead and do this, you know, what happens is that the first time through, it adds the first value and then it adds five to four and then six to nine and then seven to 15. And so, so this is just a really basic kind of an algorithm that is, you know, it's, it's important to know how it works. You know, you shouldn't leave this unit without, without understanding this. This is incredibly important. Very basic, but very important. Maybe if I want, another one is finding the maximum. You know, what I'll do is I'll set maybe I'll set a maximum value equal to a zero. And to make it a little bit inefficient, I'm not going to refer to the index here because I want to make a point. But if I say for val in a, and I can write some more complex code and I say, well, if, if val is let's say greater than m, okay, then m is going to be equal to val. Okay. And then what we'll do is we'll, we'll print out m at the end of the day. Now this is, this is what I call the king of the hill algorithm in the sense that you're, you're, you're assuming. So, so in a sequential process in a sequence, you don't, the computer doesn't get to, your brain can see all the numbers four, five, six, seven, they'll put an extra one here that kind of goes down a little bit. And I'll maybe make it a five here, comma four or something like this. And your brain can see this whole list, right? Your, your brain is a parallel processor that, that is trained, has been trained to recognize that seven is the maximum value, but that's not the way a sequential processor would, would ascertain the maximum value. It has to do with something called a linear search basically or a sequential search. The computer has to go through each element one by one by one and can only, it can only see the element that it can see right now. And once it's done with that element, it doesn't care about it anymore. It goes to the next element and the next element and the next element. And, and that's how it works. So in this case, you have, you're making the assumption that the maximum value is the zero of element on the list because you don't have any other information beyond that point. A zero is currently the winner because I'm only giving you that number. That's the only number you can see if you're a microprocessor. Then what happens is, is we start to cycle through the values. Now in this case, we unnecessarily revisit a zero because of that value being on the list. But the question is asked if the next value on the list is greater than the current maximum, what should you do? You should choose that to be the actual maximum. Okay. And, and if it isn't, then you don't, then you don't change it. And that's how that algorithm works. This kind of an algorithm I think is, is extremely important to understand how that kind of king of the hill, you know, works because if you, if you, if you're trying to sequence through or sequentially step through a list of elements and you can only look at them one by one by one by one by one. And you don't get to see the whole list. At the same time. And so then you would do something like this and you'd be told that that the maximum value is, is, is seven on the list. Okay. So I'm going to separate this out just so it becomes abundantly clear. One other thing I want to point out is, is that in, in Python. You know, there is a max function, right? So, so you don't really, you don't need to write this code. It's, it's there for you. So why is it important for someone who's just starting out in programming? Well in programming, you want to know these two algorithms like the back of your hand. They're so fundamental. Of course there are methods and functions that will compute the maximum value on a list. I don't, I don't disagree with that. That's not the issue. The issue is, do you understand how those algorithms work? That's, that's, that's what makes you a programmer. Okay. That's what makes you because what happens, you know, maybe what happens along the way is, is somebody says, well, I don't want to, I don't want to sum all the values. You know, maybe I just want to sum the values that are greater than five, for instance, right? Well, well the sum function isn't going to work anymore for you. Okay. The sum function isn't going to work. This will only, this will only sum all the values. You'd have to modify this code. So a problem would be like, okay, I only want to sum the values that are greater than seven. I have to say, you know, if Val is greater than, you know, or I said five, I think whatever I said, then, okay, then and only then do you, do you sum the next value? Okay. So, so here's the point. Okay. Is that, yeah, there's a sum function. I get it, you know, but what if you have to write code that is going to be more specific about summing values? This is quite common. We'll get to and data structures too. We'll get to sets. And I think this will become even clearer, but maybe, you know, somebody specifies to you a problem says, look at it. I only want to add values to the list where the numbers are greater than five. Well, you have to code this extra if statement in there to protect the sum from adding values that you don't want on the list, right? So this is a different kind of a problem. So now you're only adding the six and the seven. Okay. And this is why, like I said, it's important, you know, as you begin to develop that, that you're able to, you know, not just see the basic algorithm, but understand how you might have to modify that algorithm in the future. And so this I think is more instructive if you, if you, not just, you know, there's learning the language, there's learning the syntax, but then there's learning how to program and understanding algorithms. And that I think is sometimes that can get missed at an introductory level. It's like, okay, well, I know the, you know, I know what a four loop is. I know what a dictionary is. And I get it, you know, like I agree, but it's, but when, when, when you can start to begin to sort of mix all those concepts together, you know, that's when you're learning, really learning how to program because you're learning how to solve a problem, you know, using a computer language. So, so going back to, you know, the concept of indices, you know, maybe in terms of the max, I'm not just interested in the maximum value, maybe I'd like to know the index where the maximum occurred. So maybe I might say for I, you know, in, in range, I'll start counting at one because for the maximum amount of algorithm, I start out with the zeroth element. And then I have, so I've already taken into account that value. So maybe I'll say I in range one to wrong language length of a and, and then if I say if, okay, if a I is great. And then what I'll, what I'll also do is say, maybe max I is equal to zero as well. So not only am I storing the value, I want to know the index of the value where the maximum occurred. Where is the maximum on the list, you know, and do I want a unique maximum, or do I want to store all possible, because if it's not unique, what if, what if the maximum number occurs many times on the list, right. So, so there's more, you know, there's more to it than just, you know, you there are cases where you want to use the index and sometimes where you don't need it's implied, like we just did a second ago for, you know, val and a, but maybe I want to know where the maximum is so not only do I do I set max equal to a I right the maximum value, then what I'm going to do possibly is maybe set the max index, you know, equal to I as well. So I store it. And so then maybe not only will I let's say, and let's say comma space occurs at index, you know, I something like this, it's not going to be pretty but it's a statement nonetheless. And something isn't working here. So let's see what did not like what I do. Oh yeah, sure. There we go. So, so for I in range, I'm going to start counting at zero because I already used up the zero index and I assume that's the maximum. And now what I'm going to do is I'm going to say if that value is greater than the maximum then store it. And so the number seven occurs at index, at index five, one, two, three, four, zero, one, two, three. Oh, sorry. Of course. Sorry about that. Like that. There we go. It doesn't occur at index five that was I didn't want to print out I I goes I counts all the way to five no doubt. But I don't want to print out I want to I want to print out the max index, which is equal to I at the time the maximum value gets, you know, gets chosen. So what will happen is that we will only go into this if statement if I find a value that is is greater than the previous maximum that was set. So, so the maximum will change by the way like maybe I'll do this too just for the heck of it just so you see this in slow motion and this is always good to just kind of print out values and so forth is that is a we should see as this program is running and so what the loop is going to do is it sets the values the maximum M and becomes five because five was greater than four and then six becomes the winner because six is greater than five and then seven becomes the winner because seven is greater than six and then and then the loop cycles through these other values and then you don't you don't see any change because the the maximum value is seven and and you bypass these that you're not allowed into this if statement because that the ith element now as you're indexing is not greater than M okay and in addition like I said now it once you understand how the algorithm works then you can start playing more games like oh not only do I maybe I don't just want the maximum value maybe I want the index or maybe I want to you know add to my code not just to find one maximum value but to store many maxima you know that that it might occur in in a larger you know there's no guarantee that there's going to be a unique maximum value so so you might want to store locations of all the maxima you know that could happen as well so so my point is that yes there is a some function yes there is a well there is a some function up here built in there is a max function built in but to understand how the how the data is being summed to understand how the maximum value is being ascertained is is fundamental to your process you must understand these these two tricks and we're going to learn more tricks along the way but my recollection is that is that I bring this up a number of times you know between because because these are meant to be prototypical examples where I can start to introduce how to take how you write built-in functions for the next unit you know I just try and use these as prototypical examples because that's you know that's that's kind of the way we want to build so so I've said there's so enough about that like I said I think all I'm trying to do is is trying to bring up the intimate connection between data that you drop into a list you know since they're ordered you can not only index them but you can use them within loops to sequence through through a series of elements if you want to and operate them in some way either implicitly you know based upon a value or based upon their indices and if you leave the unit understanding that you know you'd make me the happiest teacher in the whole universe because that that is really a major major takeaway you know from from that unit okay so just stop and see if there are any questions because I want to get on to you know some other things that we need to discuss but well yeah I would I'd like to point out first of all a lot of thank you some hearts some thumbs up for you for so but we'll give the you know the take delay time to catch up while I do a callback to what I said earlier because we wanted to make we always want this content to be evergreen but Google's been messing with me today and I I need to make sure I'm not losing my mind because I was doing some Python research while you were talking you know because I like to have little interludes like this while we wait to see if anyone has any questions and it says the most recent stable stable release 3.9.1 and this is on Google and like that little box they give you of information was December 7th 2020 57 days ago that wasn't 57 days ago right am I crazy everyone everyone doing this is good and math that was 57 days ago that would be like 80 days ago right it's a Google is messing with me today good enough I'm checking the chat right now not just seems to be thumbs up thank yous and I think I think people are pretty on board with what's going if again if you're watching this after the fact feel free to leave a comment down below and we'll try and answer it and maybe next week's episode or you know if it gets too far apart maybe we do a little text thing that's what I got for you all right let's let's play a different game now and the game now is to begin to just briefly I want to speak to you know methods that that are given to you one thing you can do is whenever you're going to write a loop is that is that you can you can start off with what's called an empty list that it's important to know how to build to start with empty stuff as an initial condition probably the two most common ways you know is to let's say start with an empty list and I forget if there are any examples up to this point where we use the keyword none but we'll get to it you know that like none is nothing you know so you're a lot to actually have you know a keyword that means nothing but but an empty list can be created left bracket or right bracket or you can say you know B is equal to list you know something like this so so the so Python is ready ready for you to to to begin placing data within a list okay and the way the way that you do that the way that you build a list I'm just gonna again we'll start here and what kind of build because I want to kind of really open something up you know for I am range eight or something like that I don't know Rand not Rand we'll get to Rand at some point we'll need that but maybe what I want to do is I just want to create a list of of integers let's say and the append method is instrumental for doing this this is really the way that you need to be building up lists and I kind of go into this in the course a little bit when it comes to copying data into a list or putting data into a list is that this is this is really the definitive way for placing data and building data within a list so so there's a lot of different ways that you could you could build up you know information in a list it might be that you you initialize it you know by some variable like we were doing a few minutes ago with the left bracket data right bracket another thing you might do is you might do it by appending values to the list and each time you append a new value then you you know you add you add information to that list so if we ran a loop like this then what happens is as you as you run through as you run through the list it gets larger and larger and larger because you're adding more elements you know you're adding a new element every time you you know you go through the list so so a couple of things okay first of all this dot notation okay is is incredibly important again you know we'll get more into how we start building your own classes but this is typical type of object-oriented notation that says look at I've got this list a and again not I was going to really think bigger now when you use in Python it's like when you when you have an object that's let's say for example a list you get this whole package of methods that a method is something that you can call it can run it can give you answers it can compute stuff for you and one of those methods one of the most important methods I would say we're not gonna have a chance to look at all but I'll show you a list in a second is that is to append data to a list and this is the syntax for doing that so every time you call this method every time you say dot append and you chuck something in here between these parentheses then what you do is you append that information to the list and you don't have I'm just saying a loop is a place where you might use that but you might you could just as easily say you know out here I'll come back to this a second so you could just you know you could append a new element to the list and say for instance let's see what that looks like and so now what you've done is is you've appended the string you know SDF GSDFG to the list using the append method okay so many many Python editors the way that they work is is once you hit this dot and maybe if you hit like a tab key or something it depends on the IDE that you're using but usually just by virtue of the fact that you press dot or maybe after you hit dot some IDs want you to hit the tab key you get to see the whole list of methods that are afforded to you and again we'll get to a lot of these as the course goes on if you haven't seen a lot of these already but these are all the methods that you could use and apply that come part and parcel anytime you create a list so every every data type every built-in data type is derivable from something called a class and we'll get more rigorous about what that definition is but once you are accessing a class and you create what's called an object from that class so A is the object the class is list as we said at the beginning and once you create that object you are afforded all the rights and privileges that go along with anything that was defined within that class and that's very very powerful because as I said before then you can start appending stuff to a list and that's kind of the way you have to do it so or you can clear a list or you can copy a list there's so many things you can do and we'll get into the double underscore stuff when we get to the object oriented section of the course anything you see with these double lines over here is a double underscore method and like I said that's for later on even something like reverse A.reverse let's just choose that one for the heck of it and you can either type it or you can do something else it doesn't maybe and maybe we'll print this out and say print like so and oh that's what you get in none that's right this one doesn't return it doesn't return that's a terrible result so maybe we'll try something like this and we'll try that and say print A there we go try that and see and you get an error that's right I'll get into this later on is that there's some methods like sorting and reversals that don't that don't let me do it like this A.reverse that don't return the value so as if you wanted to print it out let me do it let me see so let me try and say this in shorthand notation some algorithms like sorts and reversals actually modify the array they change the array so you don't get a returned answer from the module so I don't want to go too far into this but usually when you call a function or a method you expect to get something returned that's the answer that is non-destructive to the original data type that's oftentimes one expectation but in the case of the reversal or like a sort which I haven't shown you yet what will happen is that A basically gets modified it gets reversed so this is one of the things you want to be kind of careful of and again as we go deeper into the course I'll get more into that but you can see right now from the list that A was reversed and that the old A doesn't exist anymore it got overwritten so I didn't want to use that kind of an example just yet because there are there's deeper aspects to copying data from one source to another that I'm trying to kind of tiptoe around right now but what's another one so maybe what we'll do is we'll say in this case fail to connect and let me do one more example because we're running out of time and I want to go over to strings let's see so let's say A let's just try this A dot maybe I want to pop something so maybe what I'll say is A dot pop let's say zero something like this and then print A this is a good way of doing this so the pop function what it'll do is it'll pop a value to pop means you sort of take an element and you basically take it out of a list so when you pop it off the list if I say pop the zeroth element what used to be SDF SDFG pops that element off and now I'm left with the list without that element okay so coming over to let me just come back here for a second so the list methods again of which there are many you can see the list but there's a ton of them and you should become in some sense somewhat familiar with because this is how you code in Python this is what you do you have an object and then you call different methods to operate and sort of calculate stuff in the list so this list I think is very very important okay we've got five minutes left so let me pop over to strings now the reason we revisit strings is because I hope I'm sharing this double check good the reason that we revisits the reason we revisit strings is once again is that when you create a string and it could be I want to say two things before we finish so just stay with me for a second when you create a string and maybe something like this and again you say s. you can use a bunch of methods that are afforded to you based on what you might want to do with strings you can find stuff you can count stuff and so that's that so maybe you might want to play a game and say well let me go ahead and capitalize every element and s and then so maybe I'll print s like this and I don't want to do longer strings stuff but list stuff and so that did not capitalize that let's see here let's come back over here strange and say did I get it oh ok ok it looks like it did capitalize s that's good join. This is such an important, this is such an important method. Okay, you can, you know, convert stuff to upper and lower case. That's what I want to use. So yeah, so you can use these to print upper and lower. I capitalize. Gotta get here. Thank you. Upper, like so, upper. And again, I'm just trying to move fast because I want to, I really have to say one more thing that's so important. These, like I said, you can just kind of like, is like, is play around with these to kind of see what they'll do. And, you know, if you, if you come on, there we go. There we go. You can play around with these to kind of, you see what you might want to do with strings. The last thing that I want to say with regard to indexing, and I meant to say this at the beginning, this is what I want to close with, is the reason that I'm putting strings and lists into the same unit is because the elements on the string are, you can index them just as if they were elements on a list. So if you, you know, go ahead and one of the printout, let's say s, rats. Oh boy, I spent too much time. I forgot one thing. If you go ahead and choose the zero element, you see that you're choosing this element. So you index elements just like, just like you index elements on a list. That's really the main reason that the strings and the list are in the same unit is because the fact that you can index the characters within a string, just like you would index the elements on a list, which means this by the way. And this is, this is very, very important. If I were to create a list that, you know, that does something like this, and I create a variable, you know, call it x. And so if I do something like this, and I say, well, tell me zero, one, two, three, tell me the third element on the list. Okay. So maybe what I'm going to do is I'll print x three, like so. Okay. Then if I do this, I'll print out. But what if I need to, what if I wanted to get an element, like if I put a list or a string, like a list into a list or a string into a string, what happens is, is that you're going to need to use a second index to maybe access elements on that list. So maybe I'll say, tell me the first element in the third element. Okay. Or tell me the, or the first character in the third element. So the first color, remember, start counting at zero s is the first element. So in this case, we would print this out. And so notice now, these are, these are double indices. Okay. So when it comes to accessing elements on a list or within a string, that there could be a second index that's required to access the element within an element. Okay. And so this notation means that I have a double subscript. And the double subscript says, okay, I've got some kind of an element that requires an extra index to resolve. If I leave it out, I get the whole thing, I get the whole string. But if I put it in, then I get one element out of it. And that would be the first element. If I put element two, then it would be D. I hope everyone realizes, like so. And lastly, just, I know I'm going to go a minute over. I just hope this is okay. I know we're supposed to stop at 1030. We'll be okay. Okay. And this is the thing I forgot to bring up. I was spending so much time on the on the loop stuff. But there's the colon operator for what's called slicing. And this is probably, you know, next to indexing, it's the most important, you know, aspect of of of an ordered sequence in Python. So if I take if I take X, and I want to maybe access a number of elements, not just one, you know, I could say something, well, well, we'll start counting tell me the first element and up to the third element. And this colon operator, what it's going to do in very much in the same way the way the range function works, is that is that I want to know what the starting point is. I want to know what the ending point is. And I need to know what the step is. If I leave that third, I could say, so I could do something like this and say, well, count by ones, but this is it's not necessary. Whenever you're going to count by ones, you can leave out the step. Let me let me put a few more elements on here. Okay, to make this clear is that what I'm saying here is give me the first to the second element, because remember, we always count one less than what the three is. So you're going to count from one to two in this case. So that's tell me element one, tell me element two, I could also say zero, one, two, three, four, five, six, seven, I could say, for instance, you know, give me elements one through six and count by twos. Okay. And so what'll happen is that in this case, I'll start counting at the fourth element, and then I go every other element because the step is two. So it says give me this element, then give me this element, and then give me that element. And of course, since I count to seven, then I'm going to stop because it's one less than seven, I'm going from elements two, four, and six. So this is element two, that's element four, and that's element six. And again, you can you can count backwards with slicing, you can count forward. And I'll say one more thing, one more thing is that you're allowed to use negative indices, because then what you can do is you can sort of count backwards, you know, you can actually in Python, you're allowed to have, you're allowed to have negative indices. And when you do that, this says tell me what's at the end of the list. So so with slicing, you can actually have negative indices that cause you to count backwards. And in fact, that's that would be a way to reverse a list, basically, you could do what the reverse method does, which is to is to count backwards from the end of the list. So, you know, you could say something like, you know, count from here to, I don't know, minus five in steps of negative one. And if you did something like that, then you're going backwards seven, six, five, and four, because the last element on the list is the negative one index. Okay, it's a fast way of determining the last element using a negative one is a fast way of determining the end of a list without necessarily having to know how long the list is. So it's good to have negative indices because you start counting here and now you say negative one, negative two, negative three, negative four. So again, we don't go to negative five. Okay, we don't go to negative five because we stop one, one before the number that you specify. And again, it's all born, you know, Python is like, it's all born out of the fact that that we start counting at zero because we start counting at zero. If I say, give me five things, you're going to count from zero to four in terms of the index. So you're always counting one less than the sort of the the maximum or in this case, the minimum value that you're you're specifying. So just just a quick blurb about slicing is that it's extremely powerful for grabbing large numbers of elements out of, you know, out of a out of a list. So I actually would have liked to have spent more time on that. I don't know where my brain went. But slicing is indexing. So just to summarize, indexing, very, very important, understanding the difference between indexing and element, understanding the relationship of lists and possibly even strings to loops and loop type of statements. And, and then slicing, and then also just the kind of host of methods that you're afforded when you're using either lists or strings or really any object. So I'll stop there. I'm sorry, I went a little bit over, but I just I felt I needed to say something about slicing. Well, I think that that was great. And I think that I will give like one second for, you know, I guess I have to give like 15 seconds because the tape delay or whatever. But we'll give a second for people if they have any like quick questions for us. But not for the most part, the chat's been pretty happy. You're reaching a global audience here. We got to thank you from Iraq. We got to thank you from Zambia. We got a hello from Mexico. Like so you know, I think, I think whatever tangent you thought you lost yourself on it seemed people enjoyed it quite a bit. So I will just give it another few seconds while I vamp and just say, again, this is a course on sailor.org. You can go there at CS 105 introduction to Python. We've done live streams before we will be doing another live stream at the same time next week. So, you know, maybe catch up to us. You can join us live or always they'll be saved on our YouTube channel and on the website. So you can go back leave comments. We'll go back and try and answer any questions you may have in the past or no any questions you have in the future for what we said in the past. And yeah, it just looks like nice things in the chat. And thank you, everyone. Again, we'll be back here 930 Eastern Standard Time. That's minus five GMT. You have to figure it out. Follow Sailor Academy on Twitter. And I'm sure that they'll let you now. So thank you, everyone, for joining us. As always, thank you, Dr. Sack and everyone.