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>The problem with your code is that the line</p>

<pre><code>foo = np.repeat(''.join(random.sample(letters, len(letters))), nblines)  
</code></pre>

<p>will first create a random permutation, and then repeat that same permutation nblines times. Numpy.repeat does not repeatedly invoke a function, it repeats elements of an already existing array, which you created with random.sample.</p>

<p>Another thing is that numpy is designed to work with numbers, not strings. Here is a short code snippet (without using numpy) to obtain your desired result:</p>

<pre><code>[random.sample(letters,len(letters)) for i in range(nblines)]
</code></pre>

<p>Result: similar to this:</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>I hope this helped ;)</p>

<p>PS: I see that others gave similar answers to this while I was writing it.</p>

python