The following (pseudo) code should insert only one ZERO per pair
from itertools import product
In [321]:
for p in product([[1],[2]],[[4],[5]]):
p[0].insert(0,0)
print(p)
Out [321]
([0, 1], [4])
([0, 0, 1], [5])
([0, 2], [4])
([0, 0, 2], [5])
In [322]:
for p in product([[1],[2]],[[4],[5]]):
q = p[:]
q[0].insert(0,0)
print(q)
Out [322]
([0, 1], [4])
([0, 0, 1], [5])
([0, 2], [4])
([0, 0, 2], [5])
I know that the reason is that the product()
method passes the item by reference, but ..... I cant change its behavior..
Any solution?