Sort Python Dictionary by Absolute Value of Values

Viewed 4436

Trying to build off of the advice on sorting a Python dictionary here, how would I go about printing a Python dictionary in sorted order based on the absolute value of the values?

I have tried:

sorted(mydict, key=abs(mydict.get))

But this raises the error bad operand type for abs(): 'builtin_function_or_method' abs() expects a number, not a function. Also, abs() is the return value of the function abs, and key is just expecting a function.

2 Answers
Related