Djuna
0
Q:

sort a 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

New to Communities?

Join the community