"str.contains(part)" or alternatives?

Greg Fortune lists at gregfortune.com
Thu Sep 12 00:18:23 EDT 2002

>> I think the current proposal is to move to
>>     if ll in s:
>> for this construct. Happy?
> I would like .contains more, but at least the proposal is _much_ better
> than "if s.find(part) != -1". :-)
> "if part in s" disturbs the pattern "if item in sequence" somewhat but
> that has already been weakened by "if key in dict" (that I like,
> nonetheless).
> Stefan

Why not simply use .count(part) > 0 ?  I didn't catch the first part of the 
conversation, but if I'm looking for a contains, I just do.

if(search_me.count(substr) > 0):
        print 'found'
        print 'not found'

Greg Fortune
Fortune Solutions

More information about the Python-list mailing list