Consider a dict of the following form:
dic = { "First": { 3: "Three" }, "Second": { 1: "One" }, "Third": { 2:"Two" } } I would like to sort it by the nested dic key (3, 1, 2)
I tried using the lambda function in the following manner but it returns a "KeyError: 0"
dic = sorted(dic.items(), key=lambda x: x[1][0])
The expected output would be:
{ "Second": { 1: "One" }, "Third": { 2: "Two" }, "First": { 3:"Three" } } In essence what I want to know is how to designate a nested key independently from the main dictionary key.
{"first": {3: "three", 1:"one"}, "second": {2:"two"}}?