How to remove certain lists from a list of lists using python?
- by seaworthy
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]]