title: Less than Or Greater Than Comparison as a Variable in Python
body: <p>I have a block of code in a function that does some comparisons, namely:</p>
  
  <pre><code>if customer_info['total_dls'] &lt; min_training_actions \
  or customer_info['percentage'] &gt; train_perc_cutoff:
      continue
  elif customer_id not in test_set \
  or test_set[customer_id]['total_dls'] &lt; min_testing_actions:
      num_uncertain +=1
      continue
  elif test_set[customer_id]['percentage'] &lt;= test_perc_cutoff:
      num_correct +=1
  else:
      num_incorrect +=1
  </code></pre>
  
  <p>Now sometimes I need to do those comparisons to be greater than, and sometimes I need them to be less than. All of the rest of the code is exactly the same. Now, I could just make two functions that reuse basically the same code, but before I do, is there some clean way to variabalize the comparison operator, so I could just use the same block of code and pass in the comparison as a variable? Something like: <code>compare(var1, var2, polarity)</code>. <strong>I know I can make this myself, but I'm wondering what the standard is in cases like this. Is there some pretty pythonic way of doing this I'm unaware of?</strong></p>
  
  <p>[Edit] Adding emphasis to the most important part of the question [/Edit]</p>