title: How to generate combinations with none values in a progressive manner
body: <p>I want to generate combinations (with empty values) between multiple lists in a progressive manner. For example, a=[1,2,3], b=[4,5,6], the desired output should be </p>
  
  <pre><code>[(1, None), (2, None), (3, None)]
  [(1, 4), (2, None), (3, None)]
  [(1, 5), (2, None), (3, None)]
  [(1, 6), (2, None), (3, None)]
  [(1, None), (2, 4), (3, None)]
  [(1, None), (2, 5), (3, None)]
  [(1, None), (2, 6), (3, None)]
  [(1, None), (2, None), (3, 4)]
  [(1, None), (2, None), (3, 5)]
  [(1, None), (2, None), (3, 6)]
  [(1, 4), (2, 5), (3, None)]
  [(1, 4), (2, 6), (3, None)]
  [(1, 5), (2, 6), (3, None)]
  [(1, 4), (2, None), (3, 5)]
  [(1, 4), (2, None), (3, 6)]
  [(1, 5), (2, None), (3, 6)]
  [(1, None), (2, 4), (3, 5)]
  [(1, None), (2, 4), (3, 6)]
  [(1, None), (2, 5), (3, 6)]
  [(1, 4), (2, 5), (3, 6)]
  The number of combinations is 20
  </code></pre>
  
  <p>EDIT:
  The number of results should be the sum of C(len(b),i)*C(len(a),i) for i in range(len(a)+1), meaning to choose i elements out of list "b" to be matched with i elements in list "a". In this case, 20=C(3,3)*C(3,3)+C(3,2)*C(3,2)+C(3,1)*C(3,1)+C(3,0)*C(3,0).</p>
  
  <p>I've tried the code below:</p>
  
  <pre><code>import itertools as it
  
  def create_combos(first, *rest):
      for index in range(len(first)+1):
          for i in it.product([first], *(it.combinations(j,index) for j in rest)):
              yield list(it.zip_longest(*i))
  
  count=0
  for combo in create_combos(a, b):
      print(combo)
      count+=1
  print('The number of combinations is '+str(count))
  </code></pre>
  
  <p>However, there were only 8 combinations in the output:</p>
  
  <pre><code>[(1, None), (2, None), (3, None)]
  [(1, 4), (2, None), (3, None)]
  [(1, 5), (2, None), (3, None)]
  [(1, 6), (2, None), (3, None)]
  [(1, 4), (2, 5), (3, None)]
  [(1, 4), (2, 6), (3, None)]
  [(1, 5), (2, 6), (3, None)]
  [(1, 4), (2, 5), (3, 6)]
  The number of combinations is 8
  </code></pre>
  
  <p>I think it's because the placement of numerical values is restricted. However, I couldn't think of a way to change their places without manually inserting the None values to list "b" and filtering out those unnecessary combinations, i.e. the code below:</p>
  
  <pre><code>import itertools as it
  
  def create_combos(first,rest):
      clone_rest=rest[:]
      clone_rest.insert(0,None)
      for sublist in it.product(clone_rest, repeat=len(first)):
          filtered_sublist=list(filter(None,sublist))
          if len(filtered_sublist)&lt;=1:
              yield(list(zip(first,sublist)))
          else:
              for i in range(len(filtered_sublist)-1):
                  if filtered_sublist[i]&gt;=filtered_sublist[i+1]:
                      break
              else:
                  yield(list(zip(first,sublist)))
  
  count=0
  for combo in create_combos(a,b):
      print(combo)
      count+=1
  print('The number of combinations is '+str(count))
  </code></pre>
  
  <p>Although this code managed to give me the output I want, it is apparently not efficient enough, especially when there are more lists and more values within each list. Any suggestions?</p>