Testing if string contains a substring

Jp Calderone exarkun at intarweb.us
Wed Apr 23 10:35:43 EDT 2003


On Wed, Apr 23, 2003 at 02:23:24PM +0000, Klaus Alexander Seistrup wrote:
> 
> [snip]
> 
> >>> contains = lambda haystack, needle: haystack.find(needle) > 0

  The above should be >= 0, otherwise the first example below fails.

> >>> contains('foo bar fly', 'foo')
> 1

  Jp

-- 
"One World, one Web, one Program." - Microsoft(R) promotional ad
"Ein Volk, ein Reich, ein Fuhrer." - Adolf Hitler
-- 
 up 34 days, 11:03, 4 users, load average: 1.96, 1.78, 1.70





More information about the Python-list mailing list