I want merge all elements of results
data in results:
element 0:
{'00000001': {'foo_id': 83959370, 'bar_id': 'ABCD1'}, '00000002': {'foo_id': 83959371, 'bar_id': 'ABCD2'}}
element 1:
{'00000003': {'foo_id': 83959372, 'bar_id': 'ABCD2'}, '00000004': {'foo_id': 83959373, 'bar_id': 'ABCD4'}}
element 2:
{'00000005': {'foo_id': 83959374, 'bar_id': 'ABCD3'}, '00000006': {'foo_id': 83959375, 'bar_id': 'ABCD6'}}
with ThreadPoolExecutor(max_workers=len(foo_ids_chunks)) as executor:
# Use the map method to apply the send_request function to each chunk in parallel
results = executor.map(send_request, foo_ids_chunks, [authorisation_token] * len(foo_ids_chunks))
logger.info(f"results {results}")
# Merge the results into a single list
for r in results:
logger.info(f"result {r}")
I try 2 solutions but do not work:
merged_results = [item for sublist in results for item in sublist]
merged_results = {key: value for json_dict in results for key, value in json_dict.items()}
wanted result:
{
"00000001":{
"foo_id":83959370,
"bar_id":"ABCD1"
},
"00000002":{
"foo_id":83959371,
"bar_id":"ABCD2"
},
"00000003":{
"foo_id":83959372,
"bar_id":"ABCD2"
},
"00000004":{
"foo_id":83959373,
"bar_id":"ABCD4"
},
"00000005":{
"foo_id":83959374,
"bar_id":"ABCD3"
},
"00000006":{
"foo_id":83959375,
"bar_id":"ABCD6"
}
}