title: python: how to add a collections.defaultdict(int) to another?
body: <p>Something like statement [4] is what I'd like...</p>
  
  <p>(obtained, clumsily &amp; non-optimally, via statements [5] and [6])</p>
  
  <pre><code>In [1]: from collections import defaultdict
  
  In [2]: d1 = defaultdict(int, dict(a=1, b=2, c=3))
  
  In [3]: d2 = defaultdict(int, dict(a=10, c=30, d=40))
  
  In [4]: d1 |= d2
  TypeError: unsupported operand type(s) for |=: 'collections.defaultdict' and 'collections.defaultdict'
  
  In [5]: def default_dict_add(d1, key, val): 
              d1[key] += val
  
  In [6]: [default_dict_add(d1, k, d2[k]) for k in d2.keys()]
  Out[6]: 
  [None, None, None]
  
  In [7]: d1
  defaultdict(int, {'a': 11, 'b': 2, 'c': 33, 'd': 40})
  </code></pre>
  
  <p>Similar to what you can do with sets (statement # [44]</p>
  
  <pre><code>In [42]: s1 = {1, 2, 3}
  s1 = {1, 2, 3}
  
  In [43]: s2 = {10, 30, 40}
  s2 = {10, 30, 40}
  
  In [44]: s1 |= s2
  
  In [45]: s1
  
  Out[45]: 
  {1, 2, 3, 10, 30, 40}
  </code></pre>