title: How to transpose a dictionary in python, reverse mapping?
body: <p>I have a dictionary in python which is like below.</p>
  
  <pre><code>{'abc': [1,2,3], 'def': [2,3,4], 'gh': [3,4]}
  </code></pre>
  
  <p>I want to convert it to another dictionary like this:</p>
  
  <pre><code>{
  1: 'abc',
  2: 'abc, def',
  3: 'abc, def, gh',
  4: 'def, gh'
  }
  </code></pre>
  
  <p>I wrote the following code, but got an error. How do I concatenate the values in dictionary? The order doesn't matter. thanks</p>
  
  <pre><code>old_dict=dict({'abc': [1,2,3], 'def': [2,3,4], 'gh': [3,4]})
  
  new_dict1=dict()
  for k, vlist in old_dict.items():
      for v in vlist:
          new_dict1[v]=new_dict1[v] + ", " + k
  
  Traceback (most recent call last):
    File "&lt;console&gt;", line 3, in &lt;module&gt;
  KeyError: 1
  </code></pre>