Is there a pythonic way of permuting a list of list?
<p>I have a list of lists containing unique strings and I want to produce an arbitrary number of different ways of sorting it. The list might look like the following:</p>

<pre><code>list = [[a], [b,c], [d], [e,f,g]]
</code></pre>

<p>The order of the lists need to be the same but I want to shuffle the ordering within a list and then have them in a single list, e.g</p>

<pre><code>list1 = [a,b,c,d,e,f,g]
list2 = [a,c,b,d,f,e,g]
...
...
listN = [a,c,b,d,f,g,e]
</code></pre>

<p>What is a good pythonic way of achieving this? I'm on python 2.7.</p>

<pre><code>from itertools import chain, permutations

your_list = [[a], [b,c], [d], [e,f,g]]
flattened = chain.from_iterable(your_list)
perms = permutations(flattened)
for perm in perms:
    print perm
</code></pre>

<p>References:</p>

<ul>
<li><a href="https://docs.python.org/2/library/itertools.html#itertools.permutations" rel="nofollow">permutations in Python 2</a></li>
<li><a href="https://docs.python.org/2/library/itertools.html#itertools.chain" rel="nofollow">chain in Python 2</a></li>
</ul>

python list python-2.7 permutation