Apr-07-2020, 09:57 PM
I'm not sure I understand what you're trying to do. Do you want 3 different sorts, or one sort that has preferential keys? And what information do you want to return. Do you need the initial keys or just the value objects?
This returns the keys and the names of dict in 'name' order
This returns the keys and the names of dict in 'name' order
>>> [(k, v['name']) for k,v in sorted(dico_nouveau.items(), key=lambda x: x[1]['name'])] [('21212121', 'Dupond'), ('20202020', 'Durand'), ('28790020', 'Férien')]or to just return all the dictionary objects in 'name' order:
>>> sorted(dico_nouveau.values(), key=lambda v: v['name']) [{'name': 'Dupond', 'first': 'Alain', 'notes': [11, 9.5, 5.5, 18]}, {'name': 'Durand', 'first': 'Martin', 'notes': [15, 15.5, 8, 13]}, {'name': 'Férien', 'first': 'Mélissa', 'notes': [13, 19.5, 15, 8]}]