Error in or

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Jun 12 05:41:42 EDT 2015


On Thu, 11 Jun 2015 08:40:50 -0700, subhabrata.banerji wrote:

>   if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in
>   inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*"
>   in inp1) or (''' " ''' in   inp1):

This is better written as:

    if any(substr in inp1 for substr in 
           ['AND', 'OR', 'NOT', '>', '&', 'MAYBE', '(', '*', ' " ']):
        print 'FINE'


-- 
Steve



More information about the Python-list mailing list