Hello I am new to python this may be something small but I am finding it difficult on how to get output in a specific format.
I have the following list of dict being returned
vpcs = [{'ResourceOwnerId': '111111111111', 'ResourceType': 'vpc', 'ResourceId': 'vpc-aaaaa'},
{'ResourceOwnerId': '222222222222', 'ResourceType': 'vpc', 'ResourceId': 'vpc-ccccc'}
{'ResourceOwnerId': '111111111111', 'ResourceType': 'vpc', 'ResourceId': 'vpc-ddddd'}]
Below is the snippet from my script
for vpc in vpcs:
acc_data = {
"account_number": vpc["ResourceOwnerId"],
"vpc": [vpc['ResourceId']]
}
acc_list.append(acc_data)
print(acc_list)
The output of which is following
[
{'account_number': '111111111111', 'vpc': ['vpc-aaaaa']},
{'account_number': '222222222222', 'vpc': ['vpc-ccccc']},
{'account_number': '111111111111', 'vpc': ['vpc-ddddd']}
]
Whereas I want an output like this
[
{'account_number': '111111111111', 'vpc': ['vpc-aaaaa', 'vpc-ddddd']},
{'account_number': '222222222222', 'vpc': ['vpc-ccccc']}
]
i.e. "account_number" which are same then those vpcs should be appended instead of creating a new entry. Any help would be greatly appreciated thank you