title: "Adding" Dictionaries in Python?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/877295/python-dict-add-by-valuedict-2">python dict.add_by_value(dict_2) ?</a>  </p>
  </blockquote>
  
  
  
  <p>My input is two dictionaries that have string keys and integer values. I want to add the two dictionaries so that the result has all the keys of the input dictionaries, and the values are the sum of the input dictionaries' values. </p>
  
  <p>For clarity, if a key appears in only one of the inputs, that key/value will appear in the result, whereas if the key appears in both dictionaries, the sum of values will appear in the result.</p>
  
  <p>For example, say my input is:</p>
  
  <pre><code>a = dict()
  a['cat'] = 1
  a['fish'] = 10
  a['aardvark'] = 1000
  
  b = dict()
  b['cat'] = 2
  b['dog'] = 200
  b['aardvark'] = 2000
  </code></pre>
  
  <p>I would like the result to be:</p>
  
  <pre><code>{'cat': 3, 'fish': 10, 'dog': 200, 'aardvark': 3000}
  </code></pre>
  
  <p>Knowing Python there must be a one-liner to get this done (it doesn't really have to be one line...). Any thoughts?</p>