sorted(['abc', 'acd', 'ade'], key=lambda x:(x[0],x[2]))
时间: 2023-12-02 13:28:01 浏览: 31
The sorted function sorts the given list of strings ['abc', 'acd', 'ade'] in ascending order based on the first character (x[0]) and then based on the third character (x[2]) of each string.
The lambda function used as the key parameter in the sorted function takes one argument x (each string in the list) and returns a tuple of two values - the first value is the first character of the string (x[0]) and the second value is the third character of the string (x[2]).
Therefore, the output of the sorted function would be ['abc', 'ade', 'acd'] because 'abc' and 'ade' both start with 'a', but 'abc' comes before 'ade' because 'b' comes before 'd'. 'acd' comes last because it starts with 'a' like the other two strings, but 'c' comes after 'b' and 'd'.