title: python3.x - selective arithmetic based on integer flags
body: <p>I have a list of "Z" and "N" values and am trying to complete simple arithmetic on them (addition and/or subtraction) based on a flag associated with them. For example:</p>
  
  <pre><code>Z = 10
  N = 10
  flag = 2
  </code></pre>
  
  <p>Where a value of 2 for "flag" would lead to:</p>
  
  <pre><code>Z += 1
  N -= 1
  </code></pre>
  
  <p>In the past, for multiple values of flag (i.e. a list), I have defined functions such as:</p>
  
  <pre><code>def(Z,N,flag):
     if flag==0:
        pass
     elif flag==1:
        Z+=2; N-=1
     elif flag==2:
        Z+=1; N-=1
     elif flag==3:
        Z-=2;N-=2
     return(Z,N)
  </code></pre>
  
  <p>However, this can become rather cumbersome if the number of possible flags is large (TONS of if...elif... statements) and the number of Z,N combinations I need to loop through is high. Does anyone know of a better and more efficient way to go about this logic? I have dabbled with creating dictionaries something like <code>dict={'0':pass; '1': [Z+=2;N-=1],...}</code> but quickly realized that it wouldn't work....</p>