title: How do I iterate in a cascaded format (in a for loop) over a list of unknown length in Python?
body: <p>Consider there is a list <code>A = [ [ ], [ ], ..., [ ] ]</code> (n times). And each sub-list of A contains several lists in them. What I would like to do is iterate over them simultaneously. It can easily be done using "<code>itertools.product</code>" function from the itertools library. Something like </p>
  
  <pre><code>    for i,j,k in itertools.product(A[0],A[1],A[2]):
          #my code
  </code></pre>
  
  <p>will suffice. However I don't know the length of list A. In case it is 3 I can use the above code. Currently I'm doing something like this</p>
  
  <pre><code>    if len(A) == 2:
          for i,j in itertools.product(A[0],A[1]):
              #my code
  
      elif len(A) == 3:
          for i,j,k in itertools.product(A[0],A[1],A[2]):
              #same code with minor changes to include parameter k
  
      elif len(A) == 4:
          for i,j,k,l in itertools.product(A[0],A[1],A[2],A[3]):
              #same code with minor changes to include parameter k and l
  </code></pre>
  
  <p>Since this is tedious, I wanted to know if there is a generalized solution using list comprehension or something else. I'm coding in Python.</p>