Artificial intelligent assistant

Python dictを識別番号式にする persons = [{"ID": 1001, "NAME": "YAMANE", "AGE": 31}, {"ID": 1001, "NAME": "SHIMADA", "AGE": 51}, {"ID": 1002, "NAME": "AMANE", "AGE": 13}, {"ID": 1003, "NAME": "OKADA", "AGE": 21}] ID ↓ persons[[1001][{"NAME": "YAMANE", "AGE": 31},{"NAME": "SHIMADA", "AGE": 51}], [1002][{"NAME": "AMANE", "AGE": 13}], [1003][{"NAME": "OKADA", "AGE": 21}]] pymysqlfetchalldict person_box = [] for person in persons: person_box[person['ID']] = person

defaultdict



from collections import defaultdict

persons = [{"ID": 1001, "NAME": "YAMANE", "AGE": 31},
{"ID": 1001, "NAME": "SHIMADA", "AGE": 51},
{"ID": 1002, "NAME": "AMANE", "AGE": 13},
{"ID": 1003, "NAME": "OKADA", "AGE": 21}]

person_box = defaultdict(list)
for person in persons:
person_box[person['ID']].append(person)

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 343d3951250d100a37eb65cc546f3295