why not "'in' in 'in'"?

Erik Max Francis max at alcyone.com
Wed Jun 12 22:33:38 EDT 2002


Grant Griffin wrote:

> So why is the "in" operator limited to single characters when used as
> a
> membership operator?  This peculiar lack of generality seems a bit
> (dare I say
> it?) "non-Pythonic".

On the contrary, it is exquisitely Pythonic.  You used the magic word
yourself:  _membership_.  A string is a sequence of characters, so when
testing membership with the `in' operator, the left-hand side of the
expression should be a character (really a string of length one).  `in'
tests membership, not for the existence of subsequences.  Would you have
expected

	[1, 2] in [1, 2, 3, 4]

to evaluate to true?

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Who'd ever think it / Such a squalid little ending
\__/ The American and Florence, _Chess_
    Church / http://www.alcyone.com/pyos/church/
 A lambda calculus explorer in Python.



More information about the Python-list mailing list