In Python programming, it is often important to sort the data in various ways. But when we use the sorted built-in function, we find that it has three parameters.
The first parameter is an iterative data, which can be a string, an array, a list, and so on.
The third one is whether the output is inverted.
So what's the second one? By looking at the text on the image, you can find that key is a function that iterates the order of data by defining the sort.
By looking at the data, there are probably two main ways to implement the key= function:
1, anonymous function
With this example, you can see that word is the value of each iteration, that is, from strawbe iteration to raspberry. On the right side of the lambda, the value is reversed, for example strawberry into yrrbewarts.
2, General function
This also enables the same functionality as anonymous functions.
Analysis of key in sorted function