I have two dictionaries:
x = [{'policy': 'a-b-windows2007', 'starttime': '4', 'duration': '5'},
{'policy': 'ab-server2012', 'starttime': '4', 'duration': '5'},
{'policy': 'Aa-windows', 'starttime': '4', 'duration': '5'}]
y = [{'policy': 'Windws a-b-windows2007', 'total_hosts': '160'},
{'policy': 'Windows ab-server2012', 'total_hosts': '170'},
{'policy': 'Windows Aa-windows', 'total_hosts': '180'}]
I want to have one dict by combining x and y if policy in x = policy in y. I have created regex and I am struggling how to merge them
x and y are not the same length.
My attempt so far:
for key in x:
for keys in y:
if key['policy'] == re.match('[0-9]+|\b[a-z-]+(\d)',keys['policy']):
z.update(y)
Wanted output:
z=[{policy: 'a-b-windows2007',starttime: '4', duration: '5',total_hosts:'160'},
{policy: 'ab-server2012',starttime: '4', duration: '5',total_hosts:'170'},
{policy: 'Aa-windows',starttime: '4', duration: '5',total_hosts:'180'}]