How to sort keys in dictionaire if they have the same value, Python

Viewed 37

I have a dictionaire in which the keys are strings and the values are integers. Kind of like this:

my_dict = {'100': 1,
           '90': 9,
           '180': 9,
           '65': 11,
           '56': 11,
           '74': 11}

I want to sort the keys (that are strings) in the dictionaire if they have the same value. So basically the expected result would be:

my_dict = {'100': 1, '180': 9, '90': 9 '56': 11, '65': 11, '74': 11}

Can someone help me on this one?

Thanks.

1 Answers

"90" is > than "180" because these are strings and not numbers. Strings are compared alphabetically, not numerically.

Related