[Tutor] The In Operator

Alan Gauld alan.gauld at freenet.co.uk
Thu Jul 27 09:31:20 CEST 2006


>I am trying to make my way through a book on Python ("Python 
>Ptogramming for
> the Absolute Beginner") and have run into some code in the book (and 
> on the
> author's accompanying CD) that won't work.  I suspect that it might 
> be
> because my version of Python is too old (2.1).

Your diagnosis is correct.
The in operator didn't work on dictionaries until 2.3 (I think)
It did work on lists/tuples and it worked for single characters in 
strings
(but not for substrings). By 2.43 both of the abiove failings had been 
fixed.

But you can fix it in this case easily enough:

> if "Dancing Baloney" in geek:

   if "Dancing Baloney" in geek.keys():

Should work.

Alan G. 




More information about the Tutor mailing list