 In this video, we're going to replicate these scratch custom my blocks over in Python. It's going to become a little bit redundant, which means we don't really need to do it this way. But we're going to get some practice in creating some functions and some more lists here as variables. And then I'm going to show you how to do it in a one liner towards the end of the video. Hey crew, it's The Serving Scratcher here, teacher-server programmer, and on this channel I help curious learners just like you along on your learning journeys. And welcome back to the From Scratch to Python series, where we're trying to wriggle you along into a text-based programming language. And in our case, it's Python. We're translating a scratch project into some Python language. We're about halfway through this series, so go check out the card in the top right-hand corner right now for some early videos. Otherwise, let's get stuck into it. So we need to go in and start with our splitline function. So let's go and create a function definition, call it splitline, and it's going to take a line as a parameter. Don't forget to put that colon there. Now let's store the colon position as a variable. This is a local variable. And we have a nice function that we could use for this. Let's go get it. So now we can just call that other function just by writing the function and passing in that same line. And this is going to give us the colon position because we did that in an earlier video. Now we need to go and implement these next two functions, but they don't exist yet. You can see we've got some comments here to create those function definitions. So let's go ahead and do that. So I've just written that first one on the screen. Extract the word from the line, and we need to pass it some parameters. We have two over here in our custom block, one of them is line. And the other one is the position of the colon in that line. Now this function, it just calls that slice custom block that we created in the previous, the slice between block. And remember, we want to slice from the start, which is the index of zero up until that colon position. So we can just create a new variable here, and we're going to call it word. This is a local variable that belongs to this function. And we're just going to call this function that we created earlier. We can paste that in there. And you'll see that we'll get some hints here about what we can pass into that function. So let's pass in the line. We need to pass in the first index because we want to start at it. And we're going to go up until the colon position. And the colon position, remember, we're just getting from the split line here. The last thing that we want to do here is we're going to return the word. It's a little bit of a deviation from what we're doing over here. And I'll explain why that is in a moment. But for now, let's go back up into our split line function here. And now, in our split line function, we can go get that word. And that word is just going to be equal to extracting the word from the line. This function that we just created, we're going to pass into it the line. That split line is going to get. And we're going to pass in that colon position of that line. Okay, before we get too far ahead of ourselves, let's go ahead and test this out. So you'll see down here in the console, I've just created a variable called line. And I've assigned it this string here. And I've just created that variable colon position that would exist here in split line. So what we can do is just test these functions to make sure they are working. So let's now call extract word from line. Remember, I've just pressed the run button here to make this all working. So I've got to type the function name. I'll pass in the line here. And then we're also going to pass in the colon position. And with any luck, we'll get the word dash. Great, we've got the word dash there. Now while we're here, we'll just call the function split line. We're not going to get a return value, but we just want to check to see if there are any errors. It's always good to test your work as you're working along just to see how you're going. And good, nothing happened there. If we want to see some output, we can either return a value or we could print a value here. Remember, returning a value will return something similar to dash here. And printing it will just print the output to the console screen. Okay, so we've just successfully extracted a word from the line. Now we want to extract the sentence from the line. And why not pause the video now and have a crack at doing this yourself? Because it's very similar to what we did for the word. We're going to be reusing a lot of this code and only a couple of things have changed. Go ahead and pause the video and try it for yourself. Okay, so I've just highlighted all this code and I'm going to paste it. And a couple of things I'm going to change. I'm going to change word wherever I see that. I'm going to call it the sentence. I'll change the local variable name as well. And I will change the return value. Now we no longer want to start at the zero index, the first position. We actually want to start where the colon position is. But it isn't the colon position because if we go up and check out one of our lines, if we were to slice our sentence from the colon position, we're also going to get the colon and the space. So the starting position is actually whatever the colon is plus two. So we're going to scroll back down and our starting position, yes, will be the colon position. But we can just in line, just add it two to it. And this will take that colon position assuming it's an integer value and we'll add it two to it. Okay. And this colon position plus two, the equivalent in scratch, just grabbing that operator block, the addition operator block and getting the variable and just adding two to it. That's the equivalent of how you do it in Python or the translation from scratch to Python. Now how'd you go with the final position here? There's a function that we've used earlier in the series that can return an integer value for the end of the line. Remember, it is to get the length of the line and we use our friend Len. And we can just get the length of the line here and that will give us the final value. Let's press the run button and let's test it out. Okay. So I just pressed the run button and I've got out two variables here. We need to extract the sentence from a line. So I'm just going to paste that. Let's put in our brackets. We'll pass in that line and we're going to pass in that colon position. Let's press enter and fantastic. We're getting should she try to make it dash for the car as our sentence. Let's scroll back up to our split line function as well. We've got our word. Now we want our sentence. We need to extract the sentence from the line. We're going to feed it the line and also the column position. So now we have a word and a sentence to use. We've got these greens quickly lines because we're not actually using them yet. So let's go about changing that. And what we're going to be doing is taking these variables and adding them to new lists. But you know what? We're going to save that for the next tutorial because it's not the right place to do it here. And I'll explain why that is in that next tutorial. But for now, let's go back up here to our split line. And we need to come up with our one liner and the one liner is going to replace actually all the work that we've done here in creating these functions. And yeah, you'll be saying, man, why'd you get me to do all that? Well, again, we're just getting practices with our function definitions, creating our local variables and feeding it in parameters. So it's just building up the repetitions here. But there is a way that we can do this all in one line and it's pretty neat. So you'll see here in Python how we can use a variable assignment. Remember, here's a variable with that assignment equal sign. It's not the maths equal sign. And we're assigning it to whatever is on the right hand side. And we know that when we extract a word from the line, we're assigning it whatever that word is that we extract or we slice it. There's a cool thing in Python where you can do multiple assignment at the same time. So I can do word and sentence. And we're going to call a function on line, the line that we're feeding to split line here. And the function we're going to call is split. Yeah, there's a built-in function called split. And what we can do with this built-in function is pass it what's called a delimiter. And the delimiter is the column that we've been using. We're just manually doing that in scratch. But yeah, there's a really cool automated way that we can do it in Python. So we're going to pass it that column character. And then I'm going to pass a number one. And the number one here is just telling us that we only want the first instance. So if I had multiple column characters in our line, well, it's only going to get the first one. And we'll split that line into before that delimiter and after that delimiter. If there were multiple columns, then it would take every column character would become a new chunk. So what this will return, whatever is on the left-hand side of the line, well, that's going to become our word. And whatever is on the right-hand side of the line, that is going to become our sentence. If we look down here at the console, we know whatever to the left of the column is our word. And whatever to the right is that space character and that sentence. We're probably going to have an extra space character there, but we can clean that up down the track. Now, we can just actually return that word and sentence. And to test out what that return value looks like, let's just run the program. Okay, so I'm just going to get our handy little variable here, our line. And now we're going to call split line that function. We're going to pass in the line, going to hit enter. And you can see that we've gotten our word here and we've gotten our sentence, but it's wrapped it in these brackets here or these parentheses. It looks a little bit like a list, doesn't it, from earlier tutorials. Now, this is actually just called a tuple. It's a special type of list. And a tuple is just a list basically that you can't change anymore. So I can't add anything to this. I can only read the values. But we can read these values and add them to a words list and a sentences list, which is what we'll do in the next tutorial. Now, just a couple of last things before we wrap up. Back to our delimiters here. I've used the colon character as a delimiter, but any character can be used. You could use a comma as a delimiter. You could use the number seven. You could use three sevens in a row if you really wanted to. So a delimiter is just something that you want to use to separate two chunks of text. The last thing is that I've got some links down in the description to these functions here. So the split function, the string function, and also our multiple variable assignment. And I'll also chuck some info down there on some tuples to give you some follow-up reading. And hey, if I've gotten around to it, there might even be a video of someone else's done in the top right hand corner. Well, awesome work on getting up to this stage. You are powering through this series on Python. There's only a few more videos left. I can't wait to catch you in the next one. But until then, I'll have to go find a wave and I'll see you then.