asking

mingqiang hu humingqiang5262131 at gmail.com
Wed Aug 22 03:17:24 EDT 2012


I mean any of "a","b","c" in string "adfbdfc"  makes the statement true,can
I not use a function?  suppose I got lots of substring let's say
s1="a",s2="b",s3="c" ...,not wrap them as a tuple or a list , just make the
statement as simple as possible to check if any of the value is the
substring of S="fasfasdfgbefve".

On Wed, Aug 22, 2012 at 1:17 PM, Dave Angel <d at davea.name> wrote:

> On 08/22/2012 12:17 AM, Ian Foote wrote:
> > Oops, hopefully this with indent correctly:
> >
> > def all_in(string, substrings):
> >     for substring in substrings:
> >         if substring not in string:
> >             return False
> >     return True
>
> The POP's question was ambiguous (did he want to match any of the
> substrings, or all of the substrings), but his example code:
>
>
> ("a" in "adfbdfc")  or ( "b" in "adfbdfc") or ("c" in "adfbdfc" )
>
> implements the opposite sense of what you have.  So perhaps he'd want:
>
>
> def any_in(string, substrings):
>     for substring in substrings:
>         if substring in string:
>               return True:
>     return False
>
>
> --
>
> DaveA
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120822/b6cff836/attachment.html>


More information about the Python-list mailing list