in operator for strings
Larry Bates
lbates at swamisoft.com
Tue May 25 10:39:49 EDT 2004
This can be written as:
a=('hello','test')
b='blah blah hello blah test'
reduce(lambda x,y: x and b.count(y), a)
or as a fuction:
def contains_all(a, b):
return reduce(lambda x,y: x and b.count(y), a)
Then in main program
if contains_all(a,b):
...
Larry Bates
Syscon, Inc.
"Moosebumps" <moosebumps at moosebumps.mb> wrote in message
news:TSDsc.72714$pN7.62390 at newssvr25.news.prodigy.com...
> Wouldn't it be cool if you could do this?
>
> ('hello','test') in 'blah blah hello blah test':
>
> and it would say if all elements of the list are in the string?
>
> it would be more efficient and more readable than:
>
> 'hello' in 'blah blah hello blah test' and 'test' in 'blah blah hello blah
> test'
>
>
More information about the Python-list
mailing list