in operator for strings
Heather Coppersmith
me at privacy.net
Tue May 25 07:11:45 EDT 2004
On Tue, 25 May 2004 08:56:19 GMT,
"Moosebumps" <moosebumps at moosebumps.mb> wrote:
> 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'
Untested:
def string_contains_any_of( targets, the_string ):
for target in targets:
if target in the_string:
return True
return False
string_contains_any_of( ('hello', 'test'), 'blah blah blah' )
HTH,
Heather
--
Heather Coppersmith
That's not right; that's not even wrong. -- Wolfgang Pauli
More information about the Python-list
mailing list