title: Python itertools product, but conditional?
body: <p>I have a function fun that takes several parameters p0,p1,.. For each parameter i give a list of possible values:</p>
  
  <pre><code>p0_list = ['a','b','c']
  p1_list = [5,100]
  </code></pre>
  
  <p>I can now call my function for every combination of p0,p1</p>
  
  <pre><code>for i in itertools.product(*[p0,p1]):
      print fun(i)
  </code></pre>
  
  <p>Now comes the problem: What if i already know, that the parameter p1 only has an effect on the result of fun, if p0 is 'a' or 'c'? In this case i need my list of parameter combinations to look like:</p>
  
  <pre><code>[('a', 5), ('a',100), ('b', 5), ('c',5), ('c', 100)]
  </code></pre>
  
  <p>So ('b', 100) is just omitted, as it would be an unecessary evaluation of fun.</p>
  
  <p><strong>My final Solution</strong>: </p>
  
  <pre><code>param_lists = [['p0', ['a','b','c']],['p1', [5,100]]]
  l = itertools.product(*[x[1] for x in param_lists])
  l = [x for x in l if not x[0] == 'b' or x[1]==5]
  </code></pre>
  
  <p>I used this approach for 5 parameters and various conditions and it works fine. It's pretty easy to read as well. This code is inspired by Corley Brigmans' and nmcleans' answers.</p>