1 | initial version |
As @John Palmieri suggests, use iterators instead of lists.
You are already importing product
from
the itertools module,
learn more about it, especially
izip
to replace zip.
Here is how to use iterators instead of lists.
from itertools import product
from itertools import izip
A = range(3)
B = range(2)
S = (izip(B,i) for i in product(A, repeat=len(B)))
2 | No.2 Revision |
As @John Palmieri suggests, use iterators instead of lists.
You are already importing product
from
the itertools module,
learn more about it, especially
izip
to replace zip.
Here is how to use iterators instead of lists.
from itertools import product
from itertools import izip
A = range(3)
B = range(2)
S = (izip(B,i) for i in product(A, repeat=len(B)))
To compare this code with the code quoted in the question,
S = (... for ... in ...)
.izip
instead of zip
.A good resource for learning about iterators is the SageMath thematic tutorial on comprehensions, iterators ind iterables.