Re: Search String for Word
Thank you thank you! Tim Williams wrote: > On 26 Jun 2006 08:24:54 -0700, [EMAIL PROTECTED] > <[EMAIL PROTECTED]> wrote: > > And what if I want to search for an item in a tuple, is there a > > similarly easy method? > > > > Tim Chase wrote: > > > > What's the best way to search a string for a particular word and get a > > > > booleen value indicating whether it exists in the string or not? > > > > > > >>> substring = 'foo' > > > >>> targetstring = 'blah foo bar' > > > >>> substring in targetstring > > > True > > > >>> if substring in targetstring: print 'yup' > > > yup > > >>> t = ('a', 'b', 'c', 'd', 'e') > >>> a = 'a' > >>> a in t > True > >>> y = 'y' > >>> y in t > False > > >>> t = ('test', 'black', 'white') > >>> a = 'a' > >>> [i for i in t if a in i] > ['black'] > >>> > > HTH :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Search String for Word
On 26 Jun 2006 08:24:54 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > And what if I want to search for an item in a tuple, is there a > similarly easy method? > > Tim Chase wrote: > > > What's the best way to search a string for a particular word and get a > > > booleen value indicating whether it exists in the string or not? > > > > >>> substring = 'foo' > > >>> targetstring = 'blah foo bar' > > >>> substring in targetstring > > True > > >>> if substring in targetstring: print 'yup' > > yup >>> t = ('a', 'b', 'c', 'd', 'e') >>> a = 'a' >>> a in t True >>> y = 'y' >>> y in t False >>> t = ('test', 'black', 'white') >>> a = 'a' >>> [i for i in t if a in i] ['black'] >>> HTH :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Search String for Word
And what if I want to search for an item in a tuple, is there a similarly easy method? Tim Chase wrote: > > What's the best way to search a string for a particular word and get a > > booleen value indicating whether it exists in the string or not? > > >>> substring = 'foo' > >>> targetstring = 'blah foo bar' > >>> substring in targetstring > True > >>> if substring in targetstring: print 'yup' > yup > > http://docs.python.org/lib/typesseq.html > > -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Search String for Word
I thought I'd seen that somewhere! Thanks Tim. I was previously using re.search(substring, targetstring). Tim Chase wrote: > > What's the best way to search a string for a particular word and get a > > booleen value indicating whether it exists in the string or not? > > >>> substring = 'foo' > >>> targetstring = 'blah foo bar' > >>> substring in targetstring > True > >>> if substring in targetstring: print 'yup' > yup > > http://docs.python.org/lib/typesseq.html > > -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Search String for Word
> What's the best way to search a string for a particular word and get a > booleen value indicating whether it exists in the string or not? >>> substring = 'foo' >>> targetstring = 'blah foo bar' >>> substring in targetstring True >>> if substring in targetstring: print 'yup' yup http://docs.python.org/lib/typesseq.html -tkc -- http://mail.python.org/mailman/listinfo/python-list
Search String for Word
What's the best way to search a string for a particular word and get a booleen value indicating whether it exists in the string or not? Thanks... -- http://mail.python.org/mailman/listinfo/python-list