Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #27601

Re: asking

Date 2012-08-22 04:42 +0100
From Ian Foote <ian@feete.org>
Subject Re: asking
References <CADYZVBA9i8Bd87CCPY2N7fz1MqrPB==BXh6GsN44RPHWcEGaug@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3626.1345607418.4697.python-list@python.org> (permalink)

Show all headers | View raw


On 22/08/12 03:57, mingqiang hu wrote:
> can I use just one statement to figure out if substring “a” ,"b" "c" 
> are in string "adfbdfc" ? not use the statement like
>
> ("a" in "adfbdfc") or ( "b" in "adfbdfc") or ("c" in "adfbdfc" ) 
> ,because if I have lots of substring, this could sucks

This might not be the most efficient way, but:

 >>> set("abc") <= set("adfbdfc")
True
 >>> set("abce") <= set("adfbdfc")
False

If you want to check for substrings longer than one character, this 
won't work. A solution then is to define a custom function:

def all_in(string, substrings):
for substring in substrings:
if substring not in string:
return False
return True

Ian

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: asking Ian Foote <ian@feete.org> - 2012-08-22 04:42 +0100
  Re: asking alex23 <wuwei23@gmail.com> - 2012-08-21 22:51 -0700

csiph-web