I am trying to sort a dictionary in python using sorted function, but my_dict.items() give me correct result and my_dict.keys() gives me incorrect
my_dict={"one":1, "two":2,"three":3, "four":4,"five":5}
sorted(my_dict.items(), key=lambda x:x[1], reverse=True)
Output:
[('five', 5), ('four', 4), ('three', 3), ('two', 2), ('one', 1)]
Above is correct, but I need only keys not the corresponding values, so I wrote:
sorted(my_dict.keys(), key=lambda x:x[1], reverse=True)
Output:
['two', 'four', 'one', 'five', 'three']
Above is incorrect result, what I am doing wrong? Please help me with the right solution.