title: Python: Merge two dictionaries
body: <p>Here is my current code:</p>
  <pre><code>A = {1 : &quot;one&quot;, 2 : &quot;two&quot;}
  B = {2 : &quot;dva&quot;, 3 : &quot;three&quot;}
  d = {}
  
  for key in set(list(A.keys()) + list(B.keys())):
      try:
          d.setdefault(key,[]).append(A[key])
      except KeyError:
          pass
  
      try:
          d.setdefault(key,[]).append(B[key])
      except KeyError:
          pass
  print(d)
  </code></pre>
  <p>And here is the result I'm currently getting:</p>
  <pre><code>{1: ['one'], 2: ['two', 'dva'], 3: ['three']}
  </code></pre>
  <p>What do I have to do to get a result that looks like the one below?</p>
  <pre><code>{1 : &quot;one&quot;, 2 : [&quot;two&quot;, &quot;dva&quot;], 3 : &quot;three&quot;}
  </code></pre>