 Hey, what's going on guys root of the knell here coming back at you with another Python tutorial? Let's get idle started up and let's see what we can do here now before I create a new window here a new script I want to show you guys the function that we're gonna be taking a look at today we're gonna be working with the list data types just like we have been in the last couple of videos and tutorials and Remember those are the data types that are denoted with these two braces or these two brackets And then the data would be in like commented in between them. So if we did like this is a list And I'll put in a isn't it Actually, is that right? How about that? Make sure everything is inside your string variables. All right now What we can do here is you can use our dot selector and see what we can run with these with this data type We can what sort of functions we can run sort of actions we can call and that sort of thing so if you use a Control space you can have this little window pop up or this little this little menu sort of thing And you can see the functions that you can run with these now some of these we've already taken a look at but today We're gonna check out your move function And if we pass in our at least we type in our two parentheses and we get inside I'm gonna do control backslash. We can see what we have to be working with here So you might not be able to see this here, but it says Removes the first occurrence of value and value is the mandatory parameter that we would pass to the function So if we pass in is it'll remove the first occurrence of is so this one right here right after the this But it won't it won't remove this one Because that's not the first occurrence. So if we if we run this You're gonna see nothing happens because we aren't getting returned anything What this function does is it doesn't return anything but instead modifies the original variable And since we can't check out what this data is anymore We should we should probably set it up in a val in a variable So let's do x equals and then that list that we set up We run this and we get x Now x is a this is a list is that right and now if we do x dot remove and we can run is We pass in is anyway, and we check out x once more after we've done calling that function We get this a list is that right because is that first occurrence of is and that value is has been removed Hence the function name and everything now There are a lot of interesting things we can do with this But there are still some quirks that some programmers may like some programmers may not like I myself don't like the idea that the Function is modifying my original variable. I want to be able to choose Okay, which which variables that the function returns are going to be controllable and which aren't that sort of thing so when we create this today, I'm not gonna have it modify the original value and I don't suggest that you do that sort of thing, but hey to each their own Obviously in programming there are many ways you can do one specific task And that's kind of the the beauty of it and kind of the one of the scarier parts that you never know Which is the real right way or the real best way to do something? But hey When we create when we create this function ourselves as well What we can do here is a we could we could potentially pass in other arguments Like we could determine where we should start removing or where we could end or or where we could let's see How many times you want to remove it that sort of thing have it remove all things or have it just remove this first occurrence And you know, you know how it goes so But I'm not gonna do that in this tutorial You can do that if you're on your own if you'd like obviously look with these last tutorials You can probably figure out the method or the way that we're doing this So in our case, let's get started though, but before we begin Let's check it out if we try and remove something that isn't in there. What if we just passed in Z It gives us a value error So we can work with this again in our in our function here, but hey, let's let's begin I'm gonna create a new window save this as a file dot Python Oh file dot Python not file dot put apparently I do that too often Get our started with a shebang line you a spin environment Python we can do a class Define our constructor with the initialized keyword wrapped in two underscores on either end Passing the self keyword as always because you should do that for every function that you declare inside of a class and outside of our class in the Global scope we can test if name is equal to main what that will do is it let us determine whether or not This is the the real script that we're running now inside that conditional statement We can create an object for a class our base class and everything that's inside the constructor will happen automatically because when you initialize an object Everything in that constructor will be run. So let's try it I'm not going to use the self variable preceding my keywords today I'm just preceding my I'm not going to use the self keyword preceding my variables today I think I think I said that wrong But yeah, I don't plan on using this I think you guys understand the the concept of using the self keyword it helps you realize Okay, this is a value for the for this specific object and that sort of thing, but it is sort of optional So if I do array Set this up is actually I think I have the original array still copied. There we go Now if we print out array We can see here This is a list is that right and I'm gonna I'm gonna add some new lines on here So we can see what other things we're working with and remember if we're concatenating all of the variables Have to be a string so I'm gonna turn the array into a string with our str function And I can type cast it or convert that sort of thing and now we can still display and we have some new lines on here So let's uh, let's try this again. Let's do array then we can remove is Now I remember this isn't going to return anything so we don't have to pass it to the print function But we should afterwards print out the array And I'm not going to concatenate anything on here So we don't have to run that string function But now is or at least the first occurrence of is is gone right after that this word in the first index uh index zero But now let's let's try and recreate this all on our own Let's do a define and this is uh, this is a little bit more of a Experimental thing as you guys know so I could screw up We're gonna need the self keyword. We obviously need the array that we're working with and uh, let's need the value So now what we can do is we can uh, I'm gonna find some things here. We can do a new array A new array is going to be filled with all the values except the one that we're moving So we can set up Actually, we're gonna want to loop through it first of all for Character not not so much character because it's not a string if we do for item I think that's a better name for our variable for item inside of array we can test if The value is not new array I'm sorry if the value if value is equal to Item so if item is equal to value that's probably a better way to To write this condition out So if we find something that isn't what we're trying to remove and we can just go ahead and add it to the new array So new array plus equals we're using our assignment operator here with using the plus equals So it's a relative addition and uh, we can add in the value I'm sorry the item And that should work So now if we if we run this First let's put it up or put it up here in our constructor And then after we're done looping. Anyway, we should return the new array Inside of our function. I almost forgot But now we can print out remove And we can run array and we can pass in is So let's run this and see what happens global name remove is not defined. Okay. Yeah, we need the self keyword here because that's inside our That's inside our class So you do need a soft keyword if you're defining functions at least calling functions inside of your class So if we run this we get this is a list. Is that right? And obviously that is the um, the first one that we've Printed out. That's the real array. And now when we check out ours, we have this a list that right So wait a second it removed Both occurrences of is We haven't checked for anything else. What we should do is test If we uh, um have or not So we can do here is actually set up a boolean variable. So i'm going to call mine still removing Before we loop i'm going to set this as true And uh, if item is not Else Need to do is if we are still removing If we did find what we're not looking for What we can do is if we're still removing we can do Still removing can be set to false So now in our original conditional statement, we're going to test if the item is not equal to the value So if it is we're going to completely ignore it But instead let's see If we're not still removing We can do is we can add it to The current array so new array plus equals Unpass in the item that we found Now we run this we get this a list is that right? So we found the first one But we were still removing so Because the item is not i'm sorry the item is equal to a value We will go down to our l statement here and then we'll test if we're still removing And in our case we are still removing So what we'll do is we'll set still removing to false and we won't add it We won't add it to the new array But now we keep going through the items again and again and again and eventually we get to that next The other is value inside of our array So now we're testing it again and because the item is equal to the value We're going to go down to our l statement, but we aren't still removing anymore So we're going to get this l statement and then we can add it to the new array So we get the the same functionality is what we did in the original built-in function here But we're still returning the new array So we aren't being modified inside our function. So this is kind of a good thing if we do uh When we're done printing that out we can print out the original that we've got here print out array And you can see this is the original but if we did Array is equal to self dot remove We can pass in our array here and then we can remove is or at least the first occurrence of is we run this And we've already set that variable now. We can print it out. We can print out array And now we get this a list. Is that right? So we've done everything that we've have we have here We have been able to uh decide whether or not we want to change our variable or not But we can still get the information of what it would be if we had removed it And that sort of thing so we've done our job here And now remember if you wanted to you could make this function a whole lot more advanced now that you know The way that works you could decide where you want to start iterating from if you want to do that You could be like you could be counting through the array that you're looping through and then index them Indexing them with that incremental variable that we've set up like for i in range And you can use a start and end variable to see where you're going to start removing from that sort of thing You could uh, you could decide how many times you want to remove something You could do it as many times as you'd like or you could set it up only once or twice and that sort of thing So there's a lot you can work with this you can i'm sorry It's a lot you can do with this function But you kind of have to know how to set it all up and if you watch some of the tutorials I'm sure you'll catch on to the way we set things up Especially in the the previous tutorials because we've done a lot of these interesting things With strings with list data types and you know, we can only go onward from here. So thank you guys for watching I hope you enjoyed this this little tutorial here. I hope you will be able to remove things from your list And it'll keep things easy for you and i'll see you in the next tutorial. Bye