Q:

sort dictionary

from operator import itemgetter
new_dict = sorted(data.items(), key=itemgetter(1))
0
sortedDictionary = sorted(mydictionary.keys())
3
#for dictionary d
sorted(d.items(), key=lambda x: x[1]) #for inceasing order
sorted(d.items(), key=lambda x: x[1], reverse=True) # for decreasing order
#it will return list of key value pair tuples
1

 print(sorted(key_value.items(), key = lambda kv:(kv[1], kv[0])))     

2
dictionary_items = a_dictionary.items()
sorted_items = sorted(dictionary_items)
0

New to Communities?

Join the community