I wanted to sort my dictionary in reverse order, order by nested dict key 0:
mydict = {
'key1': {0: 3, 1: ["doc1.txt", "doc2.txt"], 2: ["text1", "text2"]},
'key2': {0: 8, 1: ["doc6.txt", "doc7.txt"], 2: ["text3", "text4"]},
'key3': {0: 1, 1: ["doc8.txt", "doc9.txt"], 2: ["text7", "text8"]},
}
to have this order:
'key3': {0: 1, 1: ['doc8.txt', 'doc9.txt'], 2: ['text7', 'text8']}
'key1': {0: 3, 1: ['doc1.txt', 'doc2.txt'], 2: ['text1', 'text2']}
'key2': {0: 8, 1: ['doc6.txt', 'doc7.txt'], 2: ['text3', 'text4']}
I've tried:
import operator
sorted_dict = sorted(mydict.items(), key=operator.itemgetter(0), reverse=True)
But no success.