Memory error python computing permutations of list
<p>I want to compute all possible ways of constructing a binary list of length n with the following line</p>

<pre><code>combinations = map(list, itertools.product([0, 1], repeat=n))
</code></pre>

<p>This works fine with low n's but I want to compute this for big n's (i.e. values between 25-35). Is there a better and more efficient way of producing this list? </p>

<p>Just create the list "lazily", so as to not store the entire thing in memory at once:</p>

<pre><code>n = some-largish-value

for i in itertools.product([0, 1], repeat=n):
   result = do_something_with(list(i))
</code></pre>

python python-2.7 permutation combinatorics