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))
Did this help you? Please let me know with a comment. Thank you
Posted .

Comments (RSS)

Leave a comment