Answer the question
In order to leave comments, you need to log in
Why does the sorted function's key parameter take key = lambda x: abs(x) but not abs()?
Hello!
Why does the sorted function's key parameter take key = lambda x: abs(x) but not abs()?
And for example, if I create a function like this:
def my_abs(x=0):
abs(x)
sorted(my_list, key = my_abs())
Answer the question
In order to leave comments, you need to log in
Because you are passing as key the result of calling the abs function, not the function itself. Remove parentheses.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question