I would like to iterate over all lists of length n
whose elements sum to 2. How can you do this efficiently? Here is a very inefficient method for n = 10
. Ultimately I would like to do this for `n > 25'.
n = 10
for L in itertools.product([-1,1], repeat = n):
if (sum(L) == 2):
print L #Do something with L