Welcome to your 6th lesson, I'm Professor Seth Frey, and today we're going to learn about conditionality. So, today we've learned all kinds of things we can do with code flow? We've learned to build complexity from the very, very, very basic elements you start with, and slowly do more complex things. We've learned how to take a list of things and go through it and do the same thing to each of them. We've learned to simulate code flow in our heads. And now we're going to add another twist to code flow, which is the ability to only run some of your lines of code, if certain things are true. Otherwise, do nothing or do something else. This is a lot of basis of the logic behind code. If then else, and you'll you'll get more and more comfortable with that, we're going to take it real slow. And we're going to learn it very much in the context of an application, just like it's common to have a list and want do the same thing to every element in the list. It's very common to have a bunch of things, have a list and only want a couple of things from that list. Out of all the people in the room, I only want to congratulate the ones who have graduated. Of all the people trying to get into a bar, I only want to let in the ones who are of age. So, this filtering is going to be our sort of initial use case, our main use case for understanding introducing the idea of conditionality in python. So what does filtering look like? So we we're familiar with this syntax here, [x for x in y]. Now we're just going to add a little bit, [x for x and y if z] if something is true. So if something about x holds, then we'll include x or we'll do that thing to x. If not we're going to skip it, that's what this is going to look like. So, we remember our days of the week example, we took the abbreviation, so for every day and days take the first three letters. Now, what we're going to do is, given this day's list, which appears right here, we're going to just return the day, the unchanged. We're going to return the day for every day in days if, day sub zero and that's going to be the first element of the string equals capital S. So what's this going to do? It's going to return the entire word, the entire string if it begins with an S. We're going to get back the S days, let's run it. There we are, Sunday and Saturday, let's say, I just want the abbreviations of the S days. We learned how to do that the first time around, and there you are just the abbreviations of the S days. All that filtering down is because of this if, if I delete this if, we'll get all seven days of the week back. So we can also, and that's what this example is here, same thing. We combine the filtering and the editing to do more and more complex things. We've got another example of word finders, so I have this word list. Bandana, hyperboreal, blurb, defied and so on. And what I want to know is let's see. I want every W, so I just want the whole word back, for every W in the word list. If the very first element is equal to the very last element. Okay, so let's see bandana no, hyperboreal no, blurb yes, defied yes and so on. Polyp is going to come through hopefully in kayak, let's run it. They're blurb, deified, polyp and kayak. So again, we had a big list, we had a certain criterion that we were looking for. I want to know all the words that begin and end with the same letter, and that's what I got back, just in one line. We can do the opposite, we can get everything. This is the exact same thing, except that exclamation point means not. I want all the words that don't have the same first and last letters. So I'm going to get everything else in the list that wasn't in the first list. And I'll know that and if I combine those two lists back together, I should get my original list back. That's what's going on here, I'm going to add words caught towards missed into a new word list. Now if I sort it and I sort my original they should be identical. If I sort them alphabetically, and there I get true back, which is to say these two lists are identical, I pulled them apart and put them back together, everything makes sense. Now I've got a third example, a little more word finder. I want to give another example of the kind of conditionality you can put after that if statement. Let's say I just want the S A T words, I just want basically, I want to return a word if it's long, if it's got a lot of letters, it's a big fancy word. So let's just get the S A T words back. There they are, the longest of the two longest words. The two words are more than 10 characters, are hyperboreal and cankerousness. So this is our introduction of conditionality. We are building very, incrementally off of something we're already comfortable with. And pushing it further to show more and more things we can do with it, without adding that much more complexity.