Efficient way of testing for substring being one of a set?

Ant antroy at gmail.com
Thu Apr 3 08:44:23 EDT 2008


On Apr 3, 12:37 pm, tinn... at isbd.co.uk wrote:
> What's the neatest and/or most efficient way of testing if one of a

A different approach:

>>> words = ["he", "sh", "bla"]
>>> name = "blah"
>>> True in (word in name for word in words)
True

>>> name = "bling"
>>> True in (word in name for word in words)
False

Perhaps not as obvious or readable as Jeff's example, but is
essentially doing the same thing using generator syntax.



More information about the Python-list mailing list