擅长:python、mysql、java
<p>这就行了</p>
<pre class="lang-py prettyprint-override"><code>prev = [ { 'id': 0, 'name': 'a' }, { 'id': 1, 'name': 'b' }, { 'id': 2, 'name': 'c' } ]
current = [ { 'id': 1, 'name': 'b' }, { 'id': 2, 'name': 'c' }, { 'id': 3, 'name': 'e' }, { 'id': 4, 'name': 'f' } ]
common = []
for c in current:
if not any(c['id'] == p['id'] and c['name'] == p['name'] for p in prev):
common.append(c)
print(common)
</code></pre>
<blockquote>
<p>Return True if any element of the iterable is true. If the iterable is empty, return False</p>
</blockquote>
<p>另外,正如@wjandrea在评论中指出的,这</p>
<pre class="lang-py prettyprint-override"><code>new = [c for c in current if c not in prev]
</code></pre>
<p>这也是一个公正而美好的回答。但请注意,只有在比较整个dicts时,它才起作用</p>