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))
If you liked this posting, please feel free to leave me a comment below.
View this page on GitHub.
Posted .

Comments

Leave a Reply