 Hello, everyone. So we're going to talk about our last linked list operation, which is popping from the list. So just like a regular Python list, you can pop an index. Okay, so we don't pop by value, we pop by index. Now popping removes the item out of the list and it returns it. Okay, so Other than that, it's actually not too different than remove. So I'm going to pop over to my code, ha ha ha, right now, and I've moved myself down to the bottom and I'm just going to talk through what I expect out of this operation because there's a couple of other things going on here. But in truth, once you handle kind of these other things separately, these special cases, it does look a lot like remove. Okay, so first thing to note is just like in, well first, pop has a default parameter here. Pop pause gets none. Okay, so pause is the index, the position or index of the item to be popped. Okay, now if pause is none, here's the two scenarios that I'm talking about. So say I've got a list and I want to pop the item at index 3. Okay, if I pop the item at index 3, pause is going to be equal to 3. Okay, but if I just do this, list.pop with no parameter value, then the default parameter gets substituted in. So pause, in this case pause was assigned a 3, in this case pause will be a none. Okay? So that's what happens here. And this is to support calls just like, again, just like in a Python list, you can call pop by index, or you can call pop with nothing at all, in which case it removes and returns the very last item in the list. Okay? So, alright, that's just so you understand what how this method can be called. Alright, now what are you going to do? How are you going to approach this big problem? Well, again, it's a lot like removing, except we're not removing by value, we're removing by index. But because we are removing by index, we have to take care of a few additional special cases. And these special cases have to do with whether this index, this position that is given, is a valid one or not. Okay? So, this is getting the input and checking to make sure if it is valid. This is a pretty important concept, kind of like in programming in general. You need to know that the parameters you get for your functions are valid. Okay? So, how should you approach this? Well, the main thing is let's first let's start out with one simple special case, which is if the list is empty, what do you do? Okay? Well, I tell you right here, raise an index error. Raise an index error. So, what I'm going to type down here is kind of like pseudocode for how you need to approach this. I'll leave it up to you to write the actual code, but I'm going to recommend to you the order that you do these things in to kind of keep things straight. Okay? Now, if position is not in the range of zero to the length of the list minus one. Okay? So, we're saying, look, you can only pop valid index values. I'm not asking you to deal with like pop negative one or pop negative two, any of that. Just anything between zero and the last index in the list, whatever that is. Okay? We got to handle that, and then we got to handle the case where raise a type error if the position is not an integer, right? So if someone does list.pop Steve. Well, that's not allowed. When you call pop, it must be the index. It must be a number. Okay? So, we've got to make sure. You've got to make sure that the position is actually an integer. Okay? So I would do that first. See if it's an integer first. Okay? Make sure pause is an integer. Okay? How do you do that? Right? How can you do that? You need to, we showed this method earlier, use the type method to your advantage. Okay? It's up to you to figure out how to use it and how to research it, but use the type method. Okay? All right. Now the next thing I recommend that you do, okay, is what if this is none. Okay? What if if the pause is none, right? Pause equal equals none. What do you do? Okay? Well, if you call pop without an argument, you need to remove and return the item at the end of the list. Okay? So, what I'll suggest to you is set the position to be popped to the index of the last item. Okay? Why? Because of the next step. The final thing you need to do is check if pause is in the range, you know, this guy. Okay? If not, raise an index error. Okay? So this is going to take care of all sorts of special conditions, right? It's going to make sure that when you call pop, okay, that this thing is valid. The parameter is valid. Okay? That's the first thing you have to do. Okay? So you're going to have several if statements right at the very beginning of your method that kind of does, takes care of this stuff. All right? But I'll leave it to you to figure out what those things are, what they look like in code. But this is kind of what you need to do. All right? But also, again, understand why you're doing it. You're making sure that this parameter is a valid integer, that is an index of the list, like an index that actually exists. Okay? All right. Now, what are you going to do? So if we get to this point, at this point, the pause you are going to pop is a valid integer index. Okay? Great. So now, how do you actually do the popping? All right. How do you pop the thing out of the list? Well, if you need to pop, say, the fifth, the item at index five, then what do you got to do? You got to walk that list down to the fifth position. Okay? Well, you already know how to walk the list. We're going to walk the list with Kerr and Preve, right, just like you did in Remove, because we are going to snip things out. You got to walk the list, but instead of like searching, because before you searched for a value, now you're walking a fixed number of steps, right? If you need to pop the item at index four, you got to step down the list from the head four slots. Okay? So you're going to walk the list with Kerr and Preve, the position number of times. Okay? So you'll have a loop, you'll have a while loop that walks, but the condition for stopping that loop is a little bit different. Okay? Right? So you and you also have to like count, right? So you got to count, count the steps you take, right? Move this up. You can't see what I'm typing. Sorry. You got to count the number of steps that you take as you walk down the list. Okay? That gets you there, right? So this is like, this is like the searching step. Get to where you need to pop. Okay? And up here, this step, check that parameter is about. Okay? Now the final step, remove and return the item. Okay? Well, if you're walking Kerr and Preve, I got good news for you. This code, and if you've done everything before it correctly, and you've got current pointing to the item to be removed and Preve pointing to the item before it, this code is the same, like line for line, as the removing code in the remove method. Okay? So this Okay? You won't have to worry about this part, but it's this stuff. Okay? So the code's there. The process of snipping out the head, the tail, something in the middle, it's the same. The key is that you get Kerr and Preve pointed to the same place. So you can cut and paste this code. It'll work just fine. Okay? But you got to do all the stuff before it first. All right? So this pop method will be a little bit challenging for you, but this is the last linked list operation that you need to implement. All right? See you kind of wrap up this discussion of linked lists in the next video.