+ 1
Does anyone know the relation of 'key' in here?
L = [3,-4,-2,5,1] print(sorted(L,key = lambda x: abs(x)))
1 Antwort
+ 5
Key is the function used for sorting.
By default, it is 'lambda x: x'.
In your example, the list is sorted based on the absolute value of the elements, so the result will be [1,-2,3,-4,5].