How to sort dictionary inside dictionary?
dic={doc1: {'qq': 5, 'ww': 6, 'gg': 2}, doc2: {'xx': 1, 'cc': 9, 'hh': 4}}
I want it to be like this (sorted desc on values of inner dictionary)
dic={doc1: {'ww': 6, 'qq': 5, 'gg': 2}, doc2: {'cc': 9, 'hh': 4, 'xx': 1}}
I've looked here, but that seems to solve only particular problem. I have thousands of keys (doc3, doc4,...), so I want something more generic.
Thanks
EDIT
I figured it out. Since I can't post solution solution is here:
import operator
for q in dic:
dummydict=dic[q]
sorted_d = sorted(dummydict.items(), key=operator.itemgetter(1), reverse=True)
sortedDic[q]=dict(sorted_d)
I understand that you might say that dictionary will not necessarily preserve its order. I run on 3.6.4, and it preserves