Apr-06-2020, 06:39 PM
(Apr-06-2020, 06:34 PM)buran Wrote:data = [ {"numero":"20202020","name" : "Durand", "first":"Martin", "notes":[12,15.5,8,13]}, {"numero":"21212121","name" : "Dupond", "first":"Alain", "notes":[11,9.5,5.5,18]}, {"numero":"21202120","name" : "Bru", "first":"Mélissa", "notes":[11,19.5,15,8]}, {"numero":"20212021","name" :"Bosse", "first":"Mélissa", "notes":[13,19.5,15,8]}, {"numero":"21202120","name" : "Allard", "first":"Chloé", "notes":[11,9.5,2,8]}, {"numero":"20202020","name" : "Durand", "first":"Martin", "notes":[12,15.5,8,13]} ] new_dict = {} for element in data: (key, value), *rest = element.items() new_dict[value] = dict(rest) print(new_dict)
Output:{'20202020': {'name': 'Durand', 'first': 'Martin', 'notes': [12, 15.5, 8, 13]}, '21212121': {'name': 'Dupond', 'first': 'Alain', 'notes': [11, 9.5, 5.5, 18]}, '21202120': {'name': 'Allard', 'first': 'Chloé', 'notes': [11, 9.5, 2, 8]}, '20212021': {'name': 'Bosse', 'first': 'Mélissa', 'notes': [13, 19.5, 15, 8]}}
Thank you so much! And I will remember tag.