I have a dictionary:
d = {"A":{"a":1, "b":2, "c":3}, "B":{"a":5, "b":6, "c":7}, "C":{"a":4, "b":6, "c":7}}
I want to sort the keys "A", "B" and "C" in a list, first on the basis of numerical values of "a", then if some tie occurs on the basis of numerical values of "b" and so on.
How can I do it?
You can use:
sorted(d, key=lambda key:(d[key]['a'], d[key]['b'], d[key]['c']))
And here is a general solution in case you have an arbitrary number of elements in the inner dictionaries:
sorted(d, key=lambda key:[value for value in sorted(d[key].items())])