Check two list of dicts and filter one list to remove dicts that appear in other list
<p>I have two lists:</p>

<pre><code>a = [{'val': 'abc', 'locval': {'China':24},'key3': 'meh'},{'val': 'men', 'locval': {'China':24},'key3': 'bla'},{'val': 'men', 'locval': {'India':56},'key3': 'cheh'}]
b = [{'val': 'abc', 'locval': {'China':24},'key3': 'cheh'}, {'val': 'def', 'locval': {'India':56},'key3': 'men'}]
</code></pre>

<p>And want to remove certain items from list A (I don't mind creating a new list) that essentially are the same as the items in list B based on two specific keys - <code>locval</code> and <code>val</code>. For example, the new list should become:</p>

<pre><code>newa = [{'val': 'men', 'locval': {'China':24},'key3': 'bla'},{'val': 'men', 'locval': {'India':56},'key3': 'cheh'}]
</code></pre>

<p>How do I do this?</p>

<p>You can make a <em>set</em> of all the pairs of interesting <em>key/value</em> pairings  from the <em>b</em> list of dicts then only keep dicts from <em>a</em> that do not have the same <em>key/value</em> pairings:</p>

<pre><code>a = [{'val': 'abc', 'locval': {'China':24},'key3': 'meh'},{'val': 'men', 'locval': {'China':24},'key3': 'bla'},{'val': 'men', 'locval': {'India':56},'key3': 'cheh'}]

b = [{'val': 'abc', 'locval': {'China':24},'key3': 'cheh'}, {'val': 'def', 'locval': {'India':56},'key3': 'men'}]


st = {(tuple(d["locval"].items()), d["val"]) for d in b}

a[:] = (d for d in a if (tuple(d["locval"].items()), d["val"])  not in st)

print(a)
</code></pre>

python list dictionary unique