How to use: while not in

I’m trying to check if a list has no member as boolean operator AND, OR, NOT.

I use:

while ('AND' and 'OR' and 'NOT') not in list:
  print 'No boolean operator'

However, when my input is: a1 c2 OR c3 AND, it prints ‘No boolean operator’, which means this list is considered no boolean operator in it by using above loop sentence.

Hope somebody can help to correct.

Thanks,
Cindy

Using sets will be screaming fast if you have any volume of data

If you are willing to use sets, you have the isdisjoint() method which will check to see if the intersection between your operator list and your other list is empty.

MyOper = set(['AND', 'OR', 'NOT'])
MyList = set(['c1', 'c2', 'NOT', 'c3'])

while not MyList.isdisjoint(MyOper):
    print "No boolean Operator"

http://docs.python.org/library/stdtypes.html#set.isdisjoint

Leave a Comment