Sto cercando di ordinare OrderedDict in OrderedDict tramite chiave 'depth'. C'è qualche soluzione per ordinare quel dizionario?Come ordinare OrderedDict of OrderedDict - Python
OrderedDict([
(2, OrderedDict([
('depth', 0),
('height', 51),
('width', 51),
('id', 100)
])),
(1, OrderedDict([
('depth', 2),
('height', 51),
('width', 51),
('id', 55)
])),
(0, OrderedDict([
('depth', 1),
('height', 51),
('width', 51),
('id', 48)
])),
])
dict Ordinati dovrebbe assomigliare a questa:
OrderedDict([
(2, OrderedDict([
('depth', 0),
('height', 51),
('width', 51),
('id', 100)
])),
(0, OrderedDict([
('depth', 1),
('height', 51),
('width', 51),
('id', 48)
])),
(1, OrderedDict([
('depth', 2),
('height', 51),
('width', 51),
('id', 55)
])),
])
alcuna idea di come ottenerlo?
Ciò causerà un'eccezione se qualsiasi dict non ha 'profondità' come chiave. Questo potrebbe essere desiderato. Se non lo è, puoi assumere una chiave predefinita usando "get". – TomOnTime
Nota che '[1]' qui si riferisce ai valori di foo, al contrario dei suoi tasti, che sarebbe '[0]' – emisilva