Transform values of a dictionary to new dictionary
<p>I have a dictionary:</p>

<pre><code>{
    'doc0': {
        'individu': 1,
        'manajemen': 1,
        'tahu': 1,
        'logistik': 1,
        'transaksi': 1
    },
    'doc1': {
        'manajemen': 1,
        'transfer': 1,
        'individu':1,
        'tahu':1,
        'transaksi': 1,
        'logistik': 1
    },
    'doc2': {
        'manajemen': 1,
        'logistik': 1,
        'transaksi': 1
    }
}
</code></pre>

<p>I want use Python to transform it to the following in a new dictionary:</p>

<pre><code>{
    'doc0': {
        'individu': 1,
        'manajemen': 1,
        'tahu': 1,
        'logistik': 1,
        'transaksi': 1,
        'transfer':0
    },
    'doc1': {
        'individu': 1,
        'manajemen': 1,
        'tahu': 1,
        'logistik': 1,
        'transaksi': 1
    },
    'doc2': {
        'individu': 0,
        'manajemen': 1,
        'tahu': 0,
        'logistik': 1,
        'transaksi': 1,
        'transfer':0
    }
}
</code></pre>

<p>I'm not entirely clear what you are trying to accomplish, but to cause all the key/value pairs in dict2 to be added to dict1 or updated in dict1, you do <code>dict1.update(dict2)</code>. Example:</p>

<pre><code>&gt;&gt;&gt; dict1={"apples":14, "bananas":22}
&gt;&gt;&gt; dict2={"apples":4, "pears":7}
&gt;&gt;&gt; dict1.update(dict2)
&gt;&gt;&gt; dict1
{'apples': 4, 'bananas': 22, 'pears': 7}
</code></pre>

<p>Alternatively if you want to copy keys and values from dict2 only if the key is not already in dict1, then</p>

<pre><code>&gt;&gt;&gt; dict1={"apples":14, "bananas":22}
&gt;&gt;&gt; dict2={"apples":4, "pears":7}
&gt;&gt;&gt; for k in set(dict2.keys()) - set(dict1.keys()): 
&gt;&gt;&gt;     dict1[k]=dict2[k]
... 
&gt;&gt;&gt; dict1
{'apples': 14, 'bananas': 22, 'pears': 7}
</code></pre>

python dictionary