Slicing a python dictionary to perform operations
<p>New 2.7 user. I have the following dictionary:   </p>

<pre><code> dict1 = {'A': {'val1': '5', 'val2': '1'},
          'B': {'val1': '10', 'val2': '10'},
          'C': {'val1': '15', 'val3': '100'}}
</code></pre>

<p>I have another dictionary </p>

<pre><code> dict2 = {'val1': '10', 'val2': '16'}
</code></pre>

<p>I want to subtract the values from A in dict1 from dict2 to get:</p>

<pre><code> dict3 = {'val1': '5', 'val2': '15'}
</code></pre>

<p>If I understood your problem correctly, this should work :</p>

<pre><code># dict1 and dict2 have been initialized
dict3 = {}
for key in dict2:
    dict3[key] = str(int(dict2[key])-int(dict1["A"][key]))
</code></pre>

python dictionary