Let's get started. Python provides two ways to sort a sequence, the dot sort method and the function sorted. We'll start with the dot sort method. It operates on a list, and it doesn't return anything but it changes the order of items to be from lowest to highest. For example, on line four, we first specify the list L1, and we have the dot notation saying we're going do a method on L1, and we're going to do the sort method not passing any parameters to that sort. Once, we've executed that on line four, when we get to line five and print, a magic, L1 is going to have its items sorted from lowest to highest, minus two, then one, then three, and so on. So, let's run that. Sure enough, we get them sorted based on the print statement on line five. On line six, we're doing the same thing except, instead of sorting the first list, we're sorting L2 which has three strings in it, cherry, apple and blueberry. What does it mean for one string to be smaller than the next? Well, we use dictionary order or alphabetic order. So, apple begins with A, blueberry begins with B, so apple comes before blueberry, and we get the list apple, blueberry, cherry. Our second option is the sorted function. It sorts the items in exactly the same order, but there are a few things that are different about this way of telling Python to sort. First, of course, is that we're using the function syntax instead of the method syntax. So, no period the sequence is going to be sorted, we pass in as a parameter to the sorted function. We're going to get a value back, that's our second difference. We get a value back and we can either assign that value to a variable as we've done on line three, or we can use it in an expression. So, for example, on line five, we're passing it directly to the print function. A third difference is that when you invoke sorted on a list, it doesn't change the original list, it produces a new list that has the same items in a different order. So, when we get to line six and we print the original list, that original list won't be changed at all. So, let's run that, and you see that we get, from line three, apple, blueberry, cherry, and the same thing from line five, the same result of calling sorted is getting printed again on line five. On line six, we're asking to print whatever is the current value of L2, and that is unchanged from the original list. So, notice the difference here on lines 10 through 12, we're doing the original way. So, we see from line 11, that we invoke using the dot notation, and then we don't have to pass the list as a parameter because it's being specified before the dot when we use sort. If we then print on line 11, we see that the list L2 itself has been modified. One other minor thing to notice here is that when we call sorted, it returns a list, when we invoke the sort method as we do in this lower half on line 12, we don't get a value back, we just get the value none. All of the action of the dot sort method is a side effect, it changes L2 but it doesn't return anything useful, the value that we get back is just none. So, that's the basics of sorting in Python. For the rest of these lessons, we'll be using the sorted function rather than the sort method. It's just safer that way. We've emphasized previously how confusing things can get when you use mutation operations. So, we avoid them whenever we can. One other nice thing about the sorted method is that we can apply it to any sequence, not just to lists. We could, for example, try to sort a string rather than sorting a list. So, you might wonder what is this going to produce and I encourage you to try to pause this and make a prediction. What will this do? Is this just going to give us apple back? Well, no it's not going to give us apple, it's going to treat apple as a sequence of characters, A, P, P, L and E. So, it's going to give us a list of single letters and they're going to be in alphabetic order. So, we get A, E, L, P and P. The comparable operation will fail because we can't destructively sort strings, strings are immutable, and that's going to give us an error. This sort attribute is not available for strings. So, dot sort you can only do on lists, but the sorted function you can do even on immutable sequences like strings. Now, in general, we're going to use sorted and not sort. See you next time when we sort things from highest to lowest.