title: How to Pythonically generate lists of variable length containing exhuastive combinations of specified values?
body: <p>I'm hoping that there's a 'Pythonic' way to do this. Let's say that I have a list and an integer.</p>
  
  <pre><code>foo = [1, 2]
  bar = 2
  </code></pre>
  
  <p>I want to return a series of lists where each list is the length specified by the integer (or length -1), where the lists represent an expression of each possible combination of values in the list. So for instance, the output I'm looking for would be something like this:</p>
  
  <pre><code>&gt;&gt; [[1, 1], [1, 2], [2, 1], [2, 2]]
  </code></pre>
  
  <p>if bar was equal to three, then:</p>
  
  <pre><code>&gt;&gt; [[1, 1, 1], [1, 1, 2], [1, 2, 2], [2, 1, 2], [2, 2, 1], [1, 2, 1], [2, 1, 1], [2, 2, 2]]
  </code></pre>
  
  <p>... and so on.</p>