回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>如何比较两个<code>dict</code>列表?结果应该是dict B列表中的奇数项</p>
<p>示例:</p>
<pre><code>ldA = [{'user':"nameA", 'a':7.6, 'b':100.0, 'c':45.5, 'd':48.9},
{'user':"nameB", 'a':46.7, 'b':67.3, 'c':0.0, 'd':5.5}]
ldB =[{'user':"nameA", 'a':7.6, 'b':99.9, 'c':45.5, 'd':43.7},
{'user':"nameB", 'a':67.7, 'b':67.3, 'c':1.1, 'd':5.5},
{'user':"nameC", 'a':89.9, 'b':77.3, 'c':2.2, 'd':6.5}]
</code></pre>
<p>这里我想比较一下ldA和ldB。它应该打印下面的输出。</p>
<pre><code>ldB -> {user:"nameA", b:99.9, d:43.7}
ldB -> {user:"nameB", a:67.7, c:1.1 }
ldb -> {user:"nameC", a:89.9, b:77.3, c:2.2, d:6.5}
</code></pre>
<p>我已经完成了下面的链接,但是在那里它只返回名称,但是我想要上面那样的名称和值。</p>
<p><em><a href="https://stackoverflow.com/questions/2412562/list-of-dicts-comparision-to-match-between-lists-and-detect-value-change-in-pytho">List of Dicts comparision to match between lists and detect value changes in Python</a></em></p>