Ensure list of dicts has a dict with key for each key in list
<p>Context:
I'm using an Ajax call to return some complex JSON from a python module. I have to use a list of keys and confirm that a list of single-item dicts contains a dict with each key.</p>

<p>Example:</p>

<pre><code>mylist=['this', 'that', 'these', 'those']

mydictlist=[{'this':1},{'that':2},{'these':3}]
</code></pre>

<p>How do I know that mydictlist is missing the "those" key? Once I know that, I can append {'those':4} to mylist. Simply checking for "those" won't work since the list is dynamic. The data structure cannot change.</p>

<p>Thanks.</p>

<p>The pandas package is a great way to handle list of dicts problems. It takes all the keys and makes them column headers, values with similar keys populate the same column.</p>

<p>Check this out:</p>

<pre><code>import pandas as pd

mydictlist=[{'this':1},{'that':2},{'these':3}]

# Convert data to a DataFrame
df = pd.DataFrame(mydictlist)

# List all the column header names and check if any of the key words are missing
df.columns
</code></pre>

python