title: reverse keys (consisting of lists) and values in Python dictionary
body: <p>I have been trying to figure this out from other posts here, but couldn't.</p>
  
  <p>I have a Python dictionary</p>
  
  <pre><code>old_dict = { (1,'a') : [2],
            (2,'b') : [3,4],
            (3,'x') : [5],
            (4,'y') : [5],
            (5,'b') : [3,4], 
            (5,'c') : [6],
            }
  </code></pre>
  
  <p>I need to reverse this so that as a result I would have:</p>
  
  <pre><code>new_dict = { (6,'c') : [5],
            (5,'x') : [3],
            (5,'y') : [4],
            (4,'b') : [5, 2],
            (3,'b') : [5, 2], 
            (2,'a') : [1],
            }
  </code></pre>
  
  <p>(This describes the edges of a finite state machine, and I need to run it backwards: it has to accept the reverse inputs as it would have before)</p>
  
  <p>For instance, in old_dict, the first key was a list <code>(1, 'a') : [2]</code>, and now, this one should become <code>(2, 'a'), [1]</code> ... or <code>(4,'y') : [5]</code> becomes <code>(5,'y') : [4]</code> etc. - I hope it is understandable what I mean.</p>
  
  <p>I have been trying to solve this with list comprehensions, but no success yet.</p>
  
  <p><strong>Update:</strong> I tried <a href="https://stackoverflow.com/a/10858286/577088">F.C.</a>'s suggestion, but somehow I can't get the code to work. I inserted it into a function, like so:</p>
  
  <pre><code>old_dict1 = { (1,'a') : [2],
            (2,'b') : [3,4],
            (3,'x') : [5],
            (4,'y') : [5],
            (5,'b') : [3,4], 
            (5,'c') : [6],
            }
  
  def reverse_dict(old_dict):
      new_dict = {}
      add_to_dict = new_dict.setdefault
  
      map(lambda kv: add_to_dict(kv[0], []).append(kv[1]),   
          sum([[((x, k[1]), k[0]) for x in v] for k, v in old_dict.items()],
              []))        # sum will take this to start adding
      return new_dict
  
  new_dict1 = reverse_dict(old_dict1)
  
  print(new_dict1)
  </code></pre>
  
  <p>But I only get returned an empty dictionary <code>{}</code></p>
  
  <p>Am I doing something wrong ? (I have really very little knowledge of Python, so please forgive me if I made a mistake that's too silly ...)</p>