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

Jeff jeffober at gmail.com
Thu Apr 3 09:00:14 EDT 2008


On Apr 3, 8:44 am, Ant <ant... at gmail.com> wrote:
> 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.

That's pretty :)



More information about the Python-list mailing list