searching for strings (in a tuple) in a string

wittempj@hotmail.com martin.witte at gmail.com
Thu Jul 6 07:57:42 EDT 2006


You can get the matching elements with a list comprehension with
something like

py> a='xfsdfyysd asd x'
py> tup=('x','yy','asd')
py> [x for x in tup if x in a.split()]
['x', 'asd']

Hope this helps

manstey wrote:
> Hi,
>
> I often use:
>
> a='yy'
> tup=('x','yy','asd')
> if a in tup:
>    <...>
>
> 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?




More information about the Python-list mailing list