I have a dict d = {'a': '1', 'c': '10', 'b': '8', 'e': '11', 'g': '3', 'f': '2'}
. I want to sort the dict with numeric value of d.values()
. Required ans is ['a','f', 'g', 'b', 'c', 'e']
. I had checked here . I couldn't make it to sort according to integer value of d.values().
>>> d = {'a': '1', 'c': '10', 'b': '8', 'e': '11', 'g': '3', 'f': '2'}
>>> sorted(d, key=lambda i: int(d[i]))
['a', 'f', 'g', 'b', 'c', 'e']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With