 Hello world serving scratchy here teacher server programmer and in this video We're continuing on with our from scratch the python series to help you transition into text-based programming in previous tutorials, we have gone ahead and imported a list of spelling words that also have sentences and we've gone through and extracted the words and the sentences of a line not all the lines yet Based on this call on as a delimiter basically the character that splits the two So we've extracted a word from a line We've extracted a sentence from a line and we can wrap those in a custom block called a split line what's left to do well now we need to iterate over each of these lines and Separate out all the words into a words list and all the sentences into a sentences list So let's get stuck into it and do that First thing we're going to do is make a new list and call it words And then I'm also going to make another new list and call it Sentences these two lists are going to house the words and the sentences of our lines here and Whenever I create one of these lists and we're going to be putting them in a custom block Then I want to go ahead and reset them So I'm going to delete all of the sentences and I'm also going to delete all the words that we have there as well Next what we need to do is something similar to what we did when we were iterating over each of the character in the line We want to iterate over each of the lines in our list So to do that we're going to have to create a new variable We can't use this underscore I variable because we use it in other functions Because if we were to read the first line here and set I to one and then we'd go through and reset that underscore I variable then we would lose where we're up to in the list here So we need to have a separate variable and we're going to call this one Line num just to represent the line number that we are up to okay So I'm just going to set line number to one just to be the first line that we want to read and separate And then we can just grab a repeat block And we can go over to the variables category and grab the length of the lines because the lines is all these These are entries here in our list So we can repeat it for ten times and the thing that we want to repeat is split line We want to split the lines up, but we're not going to pass it this hard-coded line We want to go through and read each individual line and the way to do that is we can get the item number of lines So here we go. Here's item one of lines So that would refer to the dash if I just press that you can see that Changing up there if I refer to the third item it will be this apologize and boom There we are there if I go ahead and refer to the line number. So let me just go and set line number to one And we get that line number we can see line here is set to one We get the item of the current value of line number, which is one remember It will get that first item in our list, which is dash should you try make a dash for the car So what we'll do is we'll whack that in the split line And the last thing that we need to do is change the value of not I but the line number So what this will do is we'll go through and delete all the sentences all the words let's set the initial line number to one and For ten times, which is the length of this line's list We're going to split the line and we know that just splitting the line creates a word and it creates a sentence Based on the column position after we've split the line We're going to change the line number by one So one will go to two here and we'll do the same thing for the second line And we'll keep going until we've gone through this whole list and that's how we can separate them out But we're not quite done just yet because we need to start to insert the words and the sentences here and to do that We need to look at our extract word from line and extract sentence from line custom blocks here Just to jog your memory. We're just going to check out the slice custom block It's just so you can get a refresher of what it is doing. So here's that slice custom block Remember that we have a text output value that we are populating with either the word or the sentence here That's what the slice method does. So let's go back down to our extract word line And when we perform this slice operation, we can read the value of the text output and what we're going to do is add That text output To our words list if we're inside the word custom block and we'll do the exact same thing for our extract sentence from line For the sentence custom block and instead of words, we will do sentences here So we're taking that text output that we create in this slice block and we're assigning it whatever value it is to sentences in the sentence custom block and Whatever value it is in the words a custom block here Okay, and with any luck when I press this sequence of instructions We should get a words list populated and a sentences list populated. So let's click it and there we go We've got our words separated into our words list here And we've got our sentences also separated into a sentences list and yep They kind of match up what kind of they exactly match up to what we've got in our lines The last thing I'd like to do is of course Wrap up these sequence of instructions inside of a custom blocks because they're kind of just hanging here at the moment So let's go down to out my blocks Let's create a custom block and I'm going to call this one extract words and Sentences from lines. It's a bit of a mouthful But this descriptively tells us what it's going to do So now I can just read this block and I know exactly what it's going to do It's going to extract word and sentences from lines And that's pretty much it for how we're going to create the words and sentences in this tutorial Now I just want to do a bit of a review and go over what we did how this sort of work and how it all pieces together So here we're starting at the high level. We're going okay We want to read in all these lines and we want to separate the words and the sentences Okay, and the key part here is we're going to split the lines So we're going to split whatever line we have so then we go over here And this is our split line custom block and for each line We want to set the column position inside of that line I'm just going to turn off our couple of lists there on the stage So we're going to set that column position and we're going to extract the word from the line And we're going to extract the sentence from the line So that's what these two custom blocks are here and we're using another custom block called slice and We're just changing the start value the start index and the end index of that particular slice Remember a slice is just us cutting up a slab of text into a chunk So this is like the first chunk the first word and this is the second chunk for the sentence and Inside of our slice block. We want to capture what that particular slice is and we use that Using a text output. It's gonna be a little bit different in Python and a little bit easier A lot of what we're doing here is so much easier in Python, which is great And lastly, let's finish with where we started and that was getting the column position Because we needed the column position to figure out where we wanted to slice our words and sentences And we're slicing our words and sentences because we're wanting to split the line And we want you to split the line for each line in our lines list So that's how you sort of start up the top the macro view and drill down in to the details So I hope you found that a little bit useful But the way that we worked that out we created a code block We got it to do one particular thing which is pretty similar to sort of unit testing in programming as well and Then once we figured out one particular task for this kind of block We put it inside of a custom block and we gave it a really descriptive name Now one thing that I strongly encourage you to do is right click on these custom blocks and add some comments because You might want to describe what these values mean because down the track You might forget what this piece of code does or if you share this piece of code Maybe you want to have some notes for some other people to view it as well. Obviously, it's not essential But hey, it's really going to help you out down at the track to create what's called like a breadcrumb trail like in Hansel and Gretel Okay. All right, so we'll leave this tutorial here in the next tutorial We're going to be using our words and sentences to be to create a Google text-to-speech little game That will prepare us for a scratch game that we could integrate this little Scratch spelling game with so I look forward to catching you in that tutorial. See you there