Python 3.1 - Memory Error during sampling of a large list
<p>The input list can be more than 1 million numbers. When I run the following code with smaller 'repeats', its fine;</p>

<pre><code>def sample(x):
    length = 1000000 
    new_array = random.sample((list(x)),length)
    return (new_array)

def repeat_sample(x):    
    i = 0
    repeats = 100
    list_of_samples = []
    for i in range(repeats):
       list_of_samples.append(sample(x))
    return(list_of_samples)

repeat_sample(large_array)
</code></pre>

<p>However, using high repeats such as the 100 above, results in <code>MemoryError</code>. Traceback is as follows;</p>

<pre><code>Traceback (most recent call last):
  File "C:\Python31\rnd.py", line 221, in &lt;module&gt;
    STORED_REPEAT_SAMPLE = repeat_sample(STORED_ARRAY)
  File "C:\Python31\rnd.py", line 129, in repeat_sample
    list_of_samples.append(sample(x))
  File "C:\Python31\rnd.py", line 121, in sample
    new_array = random.sample((list(x)),length)
  File "C:\Python31\lib\random.py", line 309, in sample
    result = [None] * k
MemoryError
</code></pre>

<p>I am assuming I'm running out of memory. I do not know how to get around this problem.</p>

<p>Thank you for your time!</p>
