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))

Comments

Leave a Reply