title: Avoid if cases python
body: <p>I have the following code which does:</p>
  <ol>
  <li>check a schedulingStrategy</li>
  <li>According to the scheduling strategy</li>
  <li>Check the associated scheduling period</li>
  </ol>
  <p>For now I only have two scheduling strategy thus my code is pretty straight forward:</p>
  <pre class="lang-py prettyprint-override"><code>def test_scheduling_parameters(schedulingStrategy: str, schedulingPeriod: str):
      &quot;&quot;&quot;
      :param schedulingStrategy:Could be CRON_DRIVEN or TIMER_DRIVEN
      :param schedulingPeriod: If CRON would be in the form of '* * * * * ?', else XX sec (or min)
      :return:
      &quot;&quot;&quot;
      sche_strat = ['TIMER_DRIVEN', 'CRON_DRIVEN']
      if schedulingStrategy in sche_strat:
          if schedulingStrategy == 'TIMER_DRIVEN' and re.match('\d+\s(sec|min)$', schedulingPeriod):
              return True
          elif schedulingStrategy == &quot;CRON_DRIVEN&quot; and croniter.is_valid(schedulingPeriod[:-2]):
              return True
          else:
              return &quot;Error: Wrong scheduling period&quot;
      else:
          return &quot;Error: Wrong scheduling strategy&quot;
  </code></pre>
  <p>I am wondering how I can do if I have more scheduling strategy without multiplying if cases?</p>
  <p>I had an idea of having a kind of dictionnary containing, the name of strategy and a validation function, is it the best way to do it?</p>