Generating a list of random lists
<p>I'm new to Python, so I might be doing basic errors, so apologies first.</p>

<p>Here is the kind of result I'm trying to obtain : </p>

<pre><code>foo = [
    ["B","C","E","A","D"],
    ["E","B","A","C","D"],
    ["D","B","A","E","C"],
    ["C","D","E","B","A"]
]
</code></pre>

<p>So basically, a list of lists of randomly permutated letters without repeat. </p>

<p>Here is the look of what I can get so far :</p>

<pre><code>foo = ['BDCEA', 'BDCEA', 'BDCEA', 'BDCEA']
</code></pre>

<p>The main problem being that everytime is the same permutation. This is my code so far :</p>

<pre><code>import random
import numpy as np
letters = ["A", "B", "C", "D", "E"]
nblines = 4
foo = np.repeat(''.join(random.sample(letters, len(letters))), nblines)  
</code></pre>

<p>Help appreciated. Thanks</p>

<p><code>np.repeat</code> repeats the same array. Your approach would work if you changed it to:</p>

<pre><code>[''.join(random.sample(letters, len(letters))) for _ in range(nblines)]
Out: ['EBCAD', 'BCEAD', 'EBDCA', 'DBACE']
</code></pre>

<p>This is a short way of writing this:</p>

<pre><code>foo = []
for _ in range(nblines):
    foo.append(''.join(random.sample(letters, len(letters))))

foo
Out: ['DBACE', 'CBAED', 'ACDEB', 'ADBCE']    
</code></pre>

python