title: Swapping 1 with 0 and 0 with 1 in a Pythonic way
body: <p>In some part of my Python program I have a val variable that can be 1 or 0. If it's 1 I must change to 0, if it's 0 I must change to 1.</p>
  
  <p>How do you do it in a Pythonic way?</p>
  
  <pre><code>if val == 1:
      val = 0
  elif val == 0:
      val = 1
  </code></pre>
  
  <p>it's too long!</p>
  
  <p>I did:</p>
  
  <pre><code>swap = {0: 1, 1:0}
  </code></pre>
  
  <p>So I can use it:</p>
  
  <pre><code>swap[val]
  </code></pre>
  
  <p>Other ideas?</p>