Python Dictionary combining by current expression
<p>I have two dictionaries:</p>

<pre><code>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'}]
</code></pre>

<p>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</p>

<p>x and y are not the same length.</p>

<p>My attempt so far: </p>

<pre><code> for key in x:
     for keys in y:
         if key['policy'] == re.match('[0-9]+|\b[a-z-]+(\d)',keys['policy']):
             z.update(y)
</code></pre>

<p>Wanted output:</p>

<pre><code>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'}] 
</code></pre>