Python itertools.product freezes with higher numbers
<p>I have 6 variables with different ranges. I want to create possibilities pool with my code. In this example i gave 10 range for every variable but i have to give them about 200 range. But whenever i'm trying to exceed 20 range (for example 30 range) Python kills itself, and sometimes it freezes computer. Is there anyway to make it faster and stable?</p>

<p>Thanks.</p>

<pre><code>import itertools

a = [x for x in range(400,411)]
b = [x for x in range(400,411)]
c = [x for x in range(400,411)]
d = [x for x in range(400,411)]
e = [x for x in range(400,411)]
f = [x for x in range(400,411)]

fl = lambda x: x

it = filter(fl, itertools.product(a,b,c,d,e,f))

posslist = [x for x in it]

print(len(posslist))
</code></pre>

<p>Use the cartesian_product function from <a href="http://stackoverflow.com/a/11146645/5714445">here</a>Â  for an almost 60x speed up from <code>itertools.product()</code></p>

<pre><code>def cartesian_product2(arrays):

    la = len(arrays)
    arr = np.empty([len(a) for a in arrays] + [la])
    for i, a in enumerate(np.ix_(*arrays)):
        arr[...,i] = a

    return arr.reshape(-1, la)
</code></pre>

python python-3.x itertools