Unusual permutations
<p>I have few lists:</p>

<pre><code>a = [1,2,3]
b = [4,5,6]
c = [7,8,9,10]
</code></pre>

<p>How do I generate all combinations like:</p>

<pre><code>a[0], b[0]
a[1], b[1]
a[2], b[2]
a[0], b[0], c[0]
a[1], b[1], c[0]
a[2], b[2], c[0]
a[1], b[1], c[1]
a[2], b[2], c[2]
a[0], b[0], c[3]
a[1], b[1], c[3]
a[2], b[2], c[3]
.....
</code></pre>

<p>There can be only one value at a time from each list.</p>

<p>Imagine two or more lists Like a=[1,2,3] and b=[4,5,6] and c=[7,8,9] and I would like all possible pairs like (a[0], b[0]),(a[1], b[1]), (a[0], b[0], c[0])... </p>

<p>As per your example, you seem to want only <code>abc</code>-type permutations. So you either: 1) build your "permutations" explicitly, or 2) build all permutations and filter out those you do not want.</p>

<p><strong>Explicit construction</strong></p>

<ol>
<li>Build your <code>list_of_lists</code>, i.e. <code>[['a1', 'a2', 'a3'], ['b1', 'b2'], ['c1']]</code></li>
<li>Build your permutations. Use <code>itertools.product</code>, see <a href="http://stackoverflow.com/questions/798854/all-combinations-of-a-list-of-lists">All combinations of a list of lists</a></li>
<li>From each of your permutations, you might want to create several, within a loop. E.g., from <code>('a1','b1','c1')</code> get <code>('a1','b1','c1')</code> and <code>('a1','b1')</code>. That is easy.</li>
</ol>

<p>You can fill in the gaps.</p>

<p><strong>Build all and filter out</strong></p>

<p>... Probably only useful if you need something (slightly) different from what I understood.</p>

python algorithm combinations permutation