I have this piece of code
relations = dict()
relations[('a','b','c')] = 'first'
relations[('a','c','c')] = 'third'
relations[('d','b','c')] = 'second'
relations_sorted = sorted(relations.keys(), key=lambda tup: tup[1])
for key in relations_sorted:
print( key, relations[key])
This prints the dictionary sorted on the second element of the key tuple (solution found on StackOverflow).
(('d', 'b', 'c'), 'second')
(('a', 'b', 'c'), 'first')
(('a', 'c', 'c'), 'third')
How do I extend this to sorting on the combination of second, then first, then third element in the tuple? E.g.
(('a', 'b', 'c'), 'first')
(('d', 'b', 'c'), 'second')
(('a', 'c', 'c'), 'third')