Python sort ordered dict by multiple keys

Sort an ordered dictionary by more than one key:

import collections
 
collections.OrderedDict(sorted(my_dict.items(), key=lambda item: (item[1], item[0]), reverse=True))
This post is available on GitHub.
Posted .

Comments

Leave a Reply