Really struggling on how to sort a nested dictionary alphabetically only using its sub-keys. I cannot find an analogous question on here.
For instance I have:
people = {5: {'first': 'John', 'age': '27', 'last': 'Doe'},
2: {'first': 'Marie', 'age': '22', 'gender': 'Female'}}
But want:
people = {5: {'age': '27','first': 'John', 'last': 'Doe'},
2: {'age': '22','first': 'Marie', 'gender': 'Female'}}
Attempt:
import OrderedDict from collections
for d in people:
people[d] = OrderedDict(sorted(d.items()))
AttributeError: 'int' object has no attribute 'items'