Making Combination from lists using itertools
<pre><code>import itertools
a = [[2, 3], [3, 4]]
b = [[5, 6], [7, 8], [9, 10]]
c = [[11, 12], [13, 14]]
d = [[15, 16], [17, 18]]
e = [[12,16],[13,17],[14,18],[15,19]]

q=[]
q=list(itertools.combinations((a, b, b,c, c, d,e),7)
print q
</code></pre>

<p>How would I go about using the combination function from itertools properly to use list a one time, b 2 times without replacement, c 2 times without replacement, and d and e one time each?</p>

<pre><code>[[[2, 3],[5, 6],[7, 8],[11, 12],[13, 14],[15, 16],[12,16]], 
[[2, 3],[5, 6],[7, 8],[11, 12],[13, 14],[15, 16],[13,17]],
[[2, 3],[5, 6],[7, 8],[11, 12],[13, 14],[15, 16],[14,18]],
[[2, 3],[5, 6],[7, 8],[11, 12],[13, 14],[15, 16],[15,19]], 
[[2, 3],[5, 6],[7, 8],[11, 12],[13, 14],[15, 16],[12,16]],...
[[3, 4],[7, 8],[9, 10],[11, 12], [13, 14],[17, 18],[15,19]]]
</code></pre>

<p>What your are trying to achieve is the <code>Cartesian product of input iterables</code> and not the combinations of the item present in the list. Hence you have to use <a href="https://docs.python.org/3/library/itertools.html#itertools.product" rel="nofollow"><code>itertools.product()</code></a> instead.</p>

<p>In case repetition is allowed among the lists which used more than once, answer is simple:  </p>

<pre><code>&gt;&gt;&gt; import itertools
&gt;&gt;&gt; a = [1,2]
&gt;&gt;&gt; b = [3,4]
&gt;&gt;&gt; [i for i in itertools.product(a, b, b)]
[(1, 3, 3), (1, 3, 4), (1, 4, 3), (1, 4, 4), (2, 3, 3), (2, 3, 4), (2, 4, 3), (2, 4, 4)]
</code></pre>

<p>But in case <code>repetition is not allowed</code> within the same lists, it will become little nasty and you need to combine the above answer with <a href="https://docs.python.org/3/library/itertools.html#itertools.combinations" rel="nofollow"><code>combinations()</code></a> and <a href="https://docs.python.org/3/library/itertools.html#itertools.chain" rel="nofollow"><code>chain()</code></a> (same as mentioned by <a href="http://stackoverflow.com/users/1639625/tobias-k">tobias_k</a>). This code will give the list of all <code>combinations</code>:</p>

<pre><code>&gt;&gt;&gt; from itertools import chain, product, combinations
&gt;&gt;&gt; lists, counts = [a, b], [1, 2]  # to track that a is to be used once, and b twice
&gt;&gt;&gt; list(list(chain(*p)) for p in product(*(combinations(l, c) for l, c in zip(lists, counts))))
[[1, 3, 4], [2, 3, 4]]
</code></pre>

<p>However, in case you need permutations instead of combinations, you have to update the above code with <a href="https://docs.python.org/3/library/itertools.html#itertools.permutations" rel="nofollow"><code>permutations()</code></a>:</p>

<pre><code>&gt;&gt;&gt; from itertools import chain, product, permutations
&gt;&gt;&gt; list(list(chain(*p)) for p in product(*(permutations(l, c) for l, c in zip(lists, counts))))
[[1, 3, 4], [1, 4, 3], [2, 3, 4], [2, 4, 3]]
</code></pre>

python list combinations itertools