Comparing two lists of dictionaries in Python
<p>I would like to make a function that compares two lists of dictionaries in python by looking at their keys. When list A contains a dictionary that has an entry with the same key as an entry in the dictionary in list B, the function should return True.</p>

<p>Here's an example of list A and B:</p>

<pre><code>listA = [{'key1':'value1'}, {'key2':'value2'}]
listB = [{'key1':'value3'}, {'key3':'value4'}]
</code></pre>

<p>In this example the function should return True, because key1 is a match.</p>

<p>Thanks in advance.</p>

<p>Is this what you are looking for?</p>

<pre><code>def cmp_dict(a, b):
    return any(frozenset(c) &amp; frozenset(d) for c, d in zip(a, b))
</code></pre>

<p>Here is a demonstration of its usage:</p>

<pre><code>&gt;&gt;&gt; listA = [{'key1':'value1'}, {'key2':'value2'}]
&gt;&gt;&gt; listB = [{'key1':'value3'}, {'key3':'value4'}]
&gt;&gt;&gt; cmp_dict(listA, listB)
True
&gt;&gt;&gt; 
</code></pre>

python list dictionary