How to remove certain lists from a list of lists using python?
        Posted  
        
            by 
                seaworthy
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by seaworthy
        
        
        
        Published on 2012-10-26T22:33:21Z
        Indexed on 
            2012/10/26
            23:00 UTC
        
        
        Read the original article
        Hit count: 220
        
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]]
© Stack Overflow or respective owner