Re: [Tutor] checking substrings in strings

2005-08-25 Thread Alan G
 I would like to check if a certain word exists in a given string.  
 since I learned to love lists, I used
 
 if myword in mystring:
 
 ...didnt work. I have now resorted to
 

Which version of Python?

 'boo' in 'mybigbooboo'
True


Works for me in Python 2.4...

Alan G.
(Regular readers will note I now have 2.4 installed! :-)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] checking substrings in strings

2005-08-25 Thread John Fouhy
On 8/25/05, Frank Hoffsümmer [EMAIL PROTECTED] wrote:
 Hello,
 I would like to check if a certain word exists in a given string.
 since I learned to love lists, I used
 
 if myword in mystring:
 
 ...didnt work.

What version of python are you using? This was introduced in Python 2.3.

ActivePython 2.4.1 Build 245 (ActiveState Corp.) based on
Python 2.4.1 (#65, Mar 30 2005, 09:33:37) [MSC v.1310 32 bit (Intel)] on win32
Type help, copyright, credits or license for more information.
 'bar' in 'foobarbaz'
True

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] checking substrings in strings

2005-08-24 Thread Frank Hoffsümmer
Hello,
I would like to check if a certain word exists in a given string.  
since I learned to love lists, I used

if myword in mystring:

...didnt work. I have now resorted to

if mystring.find(myword) 1:

is this really the canonical way to check if myword exists in mystring?
it feels somewhat unpythonic, thats why I'm asking

thanks for any insight you might have
-frank
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor