Search code examples
pythonarrayslistnumba

Sorted dict items without lambda


I am looking for a straightforward, alternative way to writing this, without lambda:

sorted(dict.items(), key=lambda i: -i[1])

I have tried using the operator module but without success, in terms of the results.


Solution

  • import operator
    
    # ...
    sorted(dict.items(), key=operator.itemgetter(1), reverse=True)