擅长:python、mysql、java
<p>1)<strong><em>Python 3.5</em></strong>使用<code>zip()</code>函数和字典解包运算符<code>**</code>的解决方案:</p>
<pre><code>data1 = [{"qa":"o"},{"qa":"o"}]
data2 = [{"prod":"x"}, {"prod": "x"}]
new_struct = [{**x, **y} for x,y in zip(data1, data2)]
print(new_struct)
</code></pre>
<p>输出:</p>
<pre><code>[{'qa': 'o', 'prod': 'x'}, {'qa': 'o', 'prod': 'x'}]
</code></pre>
<hr/>
<p>2)<strong><em>Python<;3.5</em></strong>使用<code>dict.update()</code>方法的解决方案:</p>
<pre><code>new_struct = []
for x,y in zip(data1, data2):
x.update(y)
new_struct.append(x)
print(new_struct) # will give the same output
</code></pre>