I have a dictionary 'dict' like so:
{'Name1' : {'value1' : 3.0, 'value2' : 1.4, 'Index' : 2 },
'Name2' : {'value1' : 5.0, 'value2' : 0.1, 'Index' : 1 },
...
}
How would I sort the dictionary into a new one, based on the 'Index' field? So I want to end up as:
{'Name2' : {'value1' : 5.0, 'value2' : 0.1, 'Index' : 1 },
'Name1' : {'value1' : 3.0, 'value2' : 1.4, 'Index' : 2 },
...
}
I have tried
new_dict = sorted(dict.items(), key=lambda x: x['Index'])
but Python objects to the str as the slice.
Apart from the clunky method of iterating through and appending each item to a new dictionary what is the recommended method please?