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>first you have to take the keys out of the list of dictionaries, then compare.</p>

<pre><code>keysA = [k for x in listA for k in x.keys()]
keysB = [k for x in listB for k in x.keys()]

any(k in keysB for k in keysA)
</code></pre>

python list dictionary