I want to sort a dictionary by its values(of integers) back to a Dictionary. Like following :
di = {'h': 10, 'e':5, 'l':8}
What I want is :
sorted_di = {'e':5, 'l':8, 'h':10}
I searched a lot and got to sort it into list of tuples, like:
import operator
sorted_li = sorted(di.items(),key=operator.itemgetter(1),reverse=True)
print(sorted_li)
Gives :
[('e',5),('l':8),('h':10)]
But I want it to be a dictionary again.
Can anyone help me please??