[Python-Dev] Re: Generalizing "in" to pairs of sequences

Ka-Ping Yee ping@lfw.org
Sun, 26 Aug 2001 04:01:01 -0700 (PDT)


On Sun, 26 Aug 2001, Eric S. Raymond wrote:
> You're right.  But since a string can't be an element of a string, the
> case I'm really interested in would still work.

It's arguable.  A character can indeed be an element of a string, and
in Python characters are one-character strings.  So this violates

    x in s   <=>  there exists i such that s[i] == x

You could argue that strings should have special behaviour for "in"
to support the common case of finding a substring; then you would have
to argue on grounds of "practicality beats purity".

I might support the argument on grounds of practicality beating purity,
but i'd have to think carefully about violating the above definition.

I can see that "substring in string" would be very convenient, but then

    if char in '0123456789': ...

would suddenly have a very different meaning -- it would succeed for
char = '12'.


-- ?!ng