I can not figure out why my code does not filter out lists from a predefined list. I am trying to remove specific list using the following code.
data = [[1,1,1],[1,1,2],[1,2,1],[1,2,2],[2,1,1],[2,1,2],[2,2,1],[2,2,2]]
data = [x for x in data if x[0] != 1 and x[1] != 1]
print data
My result:
data = [[2, 2, 1], [2, 2, 2]]
Expected result:
data = [[1,2,1],[1,2,2],[2,1,1],[2,1,2],[2,2,1],[2,2,2]]
[1, 2, 1],x[0] == 1so it automatically disqualifies it. And so on and so forth...if not (x[0] == 1 and x[1] == 1)or, as the other guys suggested: becausenot (A and B)==(not A) or (not B)