Looks like it's sorting it for me, but it's sorting it based on this first item.
But I want this second item or what we call the second key to be the sorting factor.
What I'm saying is, hey, I want you to run the sort function.
And the key for the sort function when I'm sorting through everything is I want it to iterate over each item that I'm going to get that is X is going to be this tuple.And I want you to use the value which we're going to return, which is the second one.
So the key is always going to be by the second item.We're able to sort By the second item.
I created a list that contains the characters from Hello.
So when I say param, I mean parameter, or in our case it could be a variable so we can name it whatever we want
It's a way for us to quickly create lists with Python instead of looping and using append or things that we've seen before.
The way we're able to do this is to have an expression here of what we want to do with each item that we're iterating over we loop. this is now an expression of how we want to act upon each character.
Using a for loop through an iterable, we give it a variable which we're going to act upon.
we also have an option to add a conditional and say, hey, only include it into the list based on this condition, based on a true or false.
So although this makes code shorter, maybe even cleaner, it does take away a bit of its readability.
So it might be better to just create a descriptive function like generate list of even numbers or something.
The first part is what we want to do with the data.
In our case, I wanted key and value, which I was going to extract here in our for loop.I could have named this whatever I want though I could have done K and V and you might see this commonly in python code just short term for key and value.
And then I wanted to do the power of two to the value.
So then this is what I wanted to do. This is the action.This is the for loop that we did. So the for loop was, hey, extract the key and value using the dictionary dot items.
Remember I needed to have two values so I can fill in key and value. And then the value you multiply by two or to the power of two.