I have a dictionary that looks like this:
myDict = {
\'SER12346\': {\'serial_num\': \'SER12346\', \'site_location\': \'North America\'},
\'ABC12345\'
I have a solution with cmp
(I think you must use that since we use a mix of 2 keys) but it's not really pretty, I guess it can be improved:
>>> pprint(sorted(myDict.items(), cmp=lambda x, y: cmp((x[1]['site_location'], x[1]['serial_num']), (y[1]['site_location'], y[1]['serial_num']))))
[('ABC12346', {'serial_num': 'ABC12346', 'site_location': 'Europe'}),
('SER12345', {'serial_num': 'SER12345', 'site_location': 'North America'}),
('SER12346', {'serial_num': 'SER12346', 'site_location': 'North America'}),
('ABC12345', {'serial_num': 'ABC12345', 'site_location': 'South America'}),
('SER12347', {'serial_num': 'SER12347', 'site_location': 'South America'})]