python sort the values in a dictionaryi
from operator import itemgetter
new_dict = sorted(data.items(), key=itemgetter(1))
python sort the values in a dictionaryi
from operator import itemgetter
new_dict = sorted(data.items(), key=itemgetter(1))
python dictionary print key value ascending order
word_dict = { 'this': 11, 'at': 9, 'here': 5, 'why': 12, 'is': 2 }
# Sort Dictionary by value in descending order using lambda function
sorted_dict = dict( sorted(word_dict.items(),
key=lambda item: item[1],
reverse=True))
print('Sorted Dictionary: ')
print(sorted_dict)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us