Boolean Operator Confusion

Tim Chase python.list at tim.thechases.com
Fri Apr 24 17:14:50 CEST 2015


On 2015-04-24 09:00, Ian Kelly wrote:
> It is not equivalent to:
> 
>     if ("AND" in str1) or ("OR" in str1) or ("NOT" in str1):

Which python allows you to write nicely as

  if any(term in str1 for term in ["AND", "OR", "NOT"]):

The use of any()/all() has certainly improved the readability of my
code since they were added (in 2.5?).

-tkc






More information about the Python-list mailing list