Let's say I've got some results like the below from iterating thru JSON file.
{257585701: [156173119], 667512043: [228087519], 821360748: [5350676] and more }
{136607969: [13510118], 667512043: [13510118], 257585701: [13510118] and more }
{....................more data..........}
{....................more data..........}
like 100s
Now, if I wanna delete the duplicate value and append the value (from deleted duplicate value) to the original key, how can I do that? I'm hoping to get something like this:
{257585701: [156173119,13510118 ], 667512043: [228087519, 13510118], 821360748: [5350676], 136607969: [13510118]}
My codes are:
import json
filepath = '../data/' # I have subdirectories and tons of json file
with open(filepath) as stream:
data = json.load(stream)
results = {}
for item in data['info']['items']:
cid = item['id']
for trainer in item['trainer']:
tid = trainer['id']
if tid not in trainers:
trainers[tid] = []
trainers[tid].append(cid)
print(results)
# this print(results) prints the dictionary I mentioned above and they're like 100s of them.