title: How to swap keys for values in a dictionary
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1031851/python-best-way-to-exchange-keys-with-values-in-a-dictionary">Python: Best Way to Exchange Keys with Values in a Dictionary?</a>  </p>
  </blockquote>
  
  
  
  <p>Suppose that I need to swap keys for values in dictionary.</p>
  
  <p>This is what I have in mind (Assuming that the values' value is unique):</p>
  
  <pre><code>&gt;&gt;&gt; my_dict = {'x':1, 'y':2, 'z':3}
  &gt;&gt;&gt; my_dict2 = {}
  &gt;&gt;&gt; for key, val in my_dict.items():
          my_dict2[val] = key
  </code></pre>
  
  <p>Is there any other efficient way to do it?</p>