title: checking for a variable multiple times
body: <p>I am writing some analysis scripts to in which there are a lot of conditions I need to satisfy to implement the code correctly. The code looks very messy because I have to keep checking for certain things. Here is a simplified version of my problem.</p>
  <p>I have a variable name 'measurement_type'.</p>
  <p>measurement_type can be 3 values, &quot;transmission&quot;, &quot;reflection&quot;, &quot;both&quot;. I need to perform 2 different set of instructions depending on whether measurement_type is in (&quot;transmission&quot; or &quot;reflection&quot;) or measurement_type == &quot;both&quot;</p>
  <p>I going to simplify my problem here because I don't think that the actual code really matters.</p>
  <p>If <code>measurement_type in (&quot;transmission&quot;,&quot;reflection&quot;)</code> I only have to run this:</p>
  <pre><code>table = pd.DataFrame(stuff)
  arr = []
  for num in table:
      arr.append(num)
  plt.plot(stuff)
  </code></pre>
  <p>Since I have to account for <code>measurement_type == 'both'</code>, I have to run this to check for that as well:</p>
  <pre><code>table1 = pd.DataFrame(stuff)
  arr1 = []
  if measurement_type == 'both': 
      table2 =  pd.DataFrame(stuff) #always same dimensions as table1
      arr2 = []
  for j in range(len(table)):
      arr1.append(table['data'][j])
      if measurement_type == 'both':
          arr2.append(table2['data'][j]
  plt.plot(stuff)
  if measurement_type == 'both':
      plt.plot(more stuff)
  </code></pre>
  <p>I am having to run the latter because I need to take care of the possibility of <code>measurement_type = 'both'</code>
  This is getting out of hand because I am having to perform this check of whether or not &quot;both&quot; exists.</p>
  <p>Is there a better way of doing this?
  I would rather not have to type in <code>if measurement_type == 'both'</code> over and over again as my analysis scripts get longer and more complicated.</p>