python dictionary print key value ascending order

Solutions on MaxInterview for python dictionary print key value ascending order by the best coders in the world

showing results for - "python dictionary print key value ascending order"
Samuel
26 Jul 2018
1word_dict = { 'this': 11, 'at': 9, 'here': 5, 'why': 12, 'is': 2 }
2# Sort Dictionary by value in descending order using lambda function
3sorted_dict = dict( sorted(word_dict.items(),
4                           key=lambda item: item[1],
5                           reverse=True))
6print('Sorted Dictionary: ')
7print(sorted_dict)