title: Combine two dictionaries of dictionaries (Python)
body: <p>Is there an easy way to combine two dictionaries of dictionaries in Python? Here's what I need:</p>
  
  <pre><code>dict1 = {'A' : {'B' : 'C'}}
  dict2 = {'A' : {'D' : 'E'}}
  
  result = dict_union(dict1, dict2)
  # =&gt; result = {'A' : {'B' : 'C', 'D' : 'E'}}
  </code></pre>
  
  <p>I created a brute-force function that does it, but I was looking for a more compact solution:</p>
  
  <pre><code>def dict_union(train, wagon):
      for key, val in wagon.iteritems():
          if not isinstance(val, dict):
              train[key] = val
          else:
              subdict = train.setdefault(key, {})
              dict_union(subdict, val)
  </code></pre>