searching for strings (in a tuple) in a string

manstey manstey at csu.edu.au
Thu Jul 6 08:04:38 EDT 2006


I know I can do it this way. I wanted to know if there was another way.

Fredrik Lundh wrote:
> "manstey" <manstey at csu.edu.au> wrote:
>
> > but I can't find an equivalent code for:
> >
> > a='xfsdfyysd asd x'
> > tup=('x','yy','asd')
> > if tup in a:
> >   < ...>
> >
> > I can only do:
> >
> > if 'x' in a or 'yy' in a or 'asd' in a:
> >   <...>
> >
> > but then I can't make the if clause dependent on changing value of tup.
> >
> > Is there a way around this?
>
> is the "def" statement broken in your Python version ?
>
>     def findany(text, words):
>         for w in words:
>             if w in text:
>                 return True
>         return False
> 
>     if findany(a, tup):
>         ...
> 
> </F>




More information about the Python-list mailing list