Compare two list of dictionaries and create a new list with all keys and values in python
<pre><code>a = [{'a':{'a':1}}, {'b':{'b':1}}, {'c':{}}]
b = [{'a':{'a':1,'b':0}}, {'b':{'a':1}}]
</code></pre>

<p>Here I have two list of dict. I want to compare these and generate a new list like this:</p>

<pre><code>newlist = [{'a':{'a':1,'b':0}}, {'b':{'a':1,'b':1}}, {'c':{'a':0,'b':0}}]
</code></pre>

<p>A more readable way of doing it would be </p>

<pre><code>a = [{'a':{'a':1}}, {'b':{'b':1}}, {'c':{}}]
b = [{'a':{'a':1,'b':0}}, {'b':{'a':1}}]

result = {}

for c in a + b:
    for key,value in c.items():
        result[key] = dict()
        result[key]['a'] = value.get('a', 0)
        result[key]['b'] = value.get('b', 0)

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

<p>Will give you answer<br>
<code>{'c': {'a': 0, 'b': 0}, 'a': {'a': 1, 'b': 0}, 'b': {'a': 1, 'b': 0}}</code></p>

python list dictionary