Hi, I consider the list under condition that if value of numero isn't duplicated, a new dict will be issued from a list with key is numero and value is another.
But it's not valide in cases numero duplicated, it's alawys output a new dict. And I can't find reason.
I really need your help!!!! PLEASE AND THANK YOU!!!
But it's not valide in cases numero duplicated, it's alawys output a new dict. And I can't find reason.
I really need your help!!!! PLEASE AND THANK YOU!!!
[ {"numero":"20202020","name" : "Durand", "first":"Martin", "notes":[15,15.5,8,13]}, {"numero":"21212121","name" : "Dupond", "first":"Alain", "notes":[11,9.5,5.5,18]}, {"numero":"28790020","name" : "Férien", "first":"Mélissa", "notes":[13,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,17]}, {"numero":"29019022","name" : "Durand", "first":"Alan", "notes":[12,15.5,8,13]} ] import json def check(seq): new_dict = {} for i in seq: for j in seq: if (j!=i and (i['numero'] == j['numero'])): print("Numero en double!\n " + "----> " + i['numero'] + " \n Fichier non utilisable!") else: (key, value), *rest = i.items() new_dict[value] = dict(rest) return new_dict with open('source1bad1.json', 'r', encoding="utf-8") as liste: f = json.load(liste) print(check(f))
Output:{'20202020': {'name': 'Durand', 'first': 'Martin', 'notes': [15, 15.5, 8, 13]}, '21212121': {'name': 'Dupond', 'first': 'Alain', 'notes': [11, 9.5, 5.5, 18]}, '28790020': {'name': 'Férien', 'first': 'Mélissa', 'notes': [13, 19.5, 15, 8]}, '20212021': {'name': 'Bosse', 'first': 'Mélissa', 'notes': [13, 19.5, 15, 8]}, '21202120': {'name': 'Allard', 'first': 'Chloé', 'notes': [11, 9.5, 2, 17]}, '29019022': {'name': 'Durand', 'first': 'Alan', 'notes': [12, 15.5, 8, 13]}}
or
Numero duplicated
----> (numero)