I have already build a dictionary.Here is my dictionary:
mydict = {'to': 12, 'and': 35, 'Python': 26, 'for': 49}
I want to sort this dictionary by value (from max to min) and print result like this:
for 49
and 35
Python 26
to 12
I don't know how to do it.Any help will be appreciated! I have tried:
(1) for key,value in mydict.items():
print(key,sorted(mydict.values(),reverse=True)) #int is not iterable
(2)use dict.keys() and dict.values(), but I don't know how to print correspond keys.
(3)I tried to build a list for value and build a new dictionary from value's list.But I don't know how to do it.
(4)try to convert int to string,but it can't be converted! Thank you so much!