title: Cartesian product using python without itertools
body: <p>I came across this nice line of python code for cartesian product of n number of lists that I would like to bring back on multiple lines :</p>
  
  <pre><code>def cart_product_1(*seqs):
      if not seqs:
          return [[]]
      else:
          return [[x] + p for x in seqs[0] for p in cart_product_1(*seqs[1:])]
  </code></pre>
  
  <p>This seemed pretty straightforward to me, but obviously I'm missing something here. I'm thinking I need to append a list somewhere but can't quite figure it out.</p>
  
  <pre><code>def cart_product_1(result,*seqs):
      if not seqs:
          return [[]]
      else:
          for x in seqs[0]:                       
              for p in cart_product_1(result,*seqs[1:]):
                   result.append([x]+p)
          return result
  </code></pre>
  
  <p>This leads to a MemoryError.</p>