I'm fairly new to python world and found it very interesting thus far, however, finding difficulties with the use case below, any help is appreciated.
I have 2 dict's which has same keys but different values, using set via symmetric difference I was able to get a list of tuples from the 2 dicts, but not sure how I could transform it to a result that i'm expecting.
mydict1 = {
"KMSKeyId": "arn:aws:kms:us-east-1:12345:alias/key_name",
"Subnets": "subnet-123,subnet-456",
"VpcId": "vpc-123",
"Region": "us-east-1",
"SecurityGroups": "sg-123,sg-456",
"ProxyHost": "my-custom-proxy-us-east-1.aws.com"
}
mydict2 = {
"KMSKeyId": "arn:aws:kms:us-west-1:12345:alias/key_name",
"Subnets": "subnet-789,subnet-1011",
"VpcId": "vpc-456",
"SecurityGroups": "sg-789,sg-1011",
"Region": "us-west-1",
"ProxyHost": "my-custom-proxy-us-west-1.aws.com"
}
Expected result
result = {
"us-east-1": {
"KMSKeyId": "arn:aws:kms:us-east-1:12345:alias/key_name",
"Subnets": "subnet-123,subnet-456",
"VpcId": "vpc-123",
"SecurityGroups": "sg-123,sg-456",
"ProxyHost": "my-custom-proxy-us-east-1.aws.com"
},
"us-west-1": {
"KMSKeyId": "arn:aws:kms:us-west-1:12345:alias/key_name",
"Subnets": "subnet-789,subnet-1011",
"VpcId": "vpc-456",
"SecurityGroups": "sg-789,sg-1011",
"ProxyHost": "my-custom-proxy-us-west-1.aws.com"
}
}
print(list(set(mydict1.items()) ^ set(mydict2.items()))) yields ---->
[('SecurityGroups', 'sg-789,sg-1011'),
('ProxyHost', 'my-custom-proxy-us-east-1.aws.com'),
('Subnets', 'subnet-123,subnet-456'),
('SecurityGroups', 'sg-123,sg-456'),
('Subnets', 'subnet-789,subnet-1011'),
('KMSKeyId', 'arn:aws:kms:us-west-1:12345:alias/key_name'),
('Region', 'us-east-1'),
('ProxyHost', 'my-custom-proxy-us-west-1.aws.com'),
('VpcId', 'vpc-456'),
('Region', 'us-west-1'),
('KMSKeyId', 'arn:aws:kms:us-east-1:12345:alias/key_name'),
('VpcId', 'vpc-123')]
From the above tuple list, not sure how I could get the expected result. Using the FakeDict
described here, https://stackoverflow.com/a/29520802/2101043, was able to get a dict like object that has same keys and different values, however mapping the VPC, subnet and security group to the corresponding region seem to be challenging as a beginner in python