title: generating cross product for list of lists
body: <p>I have a python list like <code>[[1 2 3] [4 5] [3] [1]]</code> and I want to generate all possible permutations. The output should be something like </p>
  
  <p><code>[[1 4 3 1] [1 5 3 1] [2 4 3 1] [2 5 3 1] [3 4 3 1] [3 5 3 1]]</code></p>
  
  <p>I thought about loops but the number of nested loops would vary according to the input. Can someone suggest a good algorithm?</p>