I have a list of tuples from this:
from itertools import product
l1 = list((product((0,1), repeat = n)))
For n=4, output is the following:
[(0, 0, 0, 0),
(0, 0, 0, 1),
(0, 0, 1, 0),
(0, 0, 1, 1),
(0, 1, 0, 0),
(0, 1, 0, 1),
(0, 1, 1, 0),
(0, 1, 1, 1),
(1, 0, 0, 0),
(1, 0, 0, 1),
(1, 0, 1, 0),
(1, 0, 1, 1),
(1, 1, 0, 0),
(1, 1, 0, 1),
(1, 1, 1, 0),
(1, 1, 1, 1)]
I want to remove the tuples where at least two "1" are next to each other, for example the (0,1,1,0)
.
I tried this:
for i in l1:
for j in i:
if j==1 and j+1 == 1:
l1.remove(i)
I guess this is not working because it takes j+1 as the actual number + 1, like if j=1 it takes as 2 and etc.
What should I do differently?