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

Erik Max Francis max at alcyone.com
Thu Jun 13 01:50:16 EDT 2002


Grant Griffin wrote:

> In that case, perhaps I should have thought of a better one <wink>. 
> In
> any event, in the case of strings, I think one might stretch the
> concept
> of "membership" to include substrings.  In fact, note that since
> Python
> has no actual character type (because a character is adequately
> represented as a string of length one) the "in" operator actually
> _does_
> test membership of strings in strings.  But for some reason, it's
> limited to testing strings of length one.  Go figure!

A string is a sequence of one-character strings.  It's not a sequence of
all the subsequences of a string.

> Honest answer: although I can't see much use for that construct, I
> can't
> see much harm in it either.  So although it's probably not worth
> adding
> to Python, I'm sure _somebody_ would find a use for it.

But that's exactly the problem; if you want [1, 2] in [1, 2, 3, 4] to
return true (i.e., for the `in' operator to test substrings, not just
membership), then you have an ambiguity problem.  A list can contain
sublists as elements, after all.

> But anyway, let's "just say no" to the tuple case rather than confuse
> ourselves; let's just make the string version of "in" a special case.

Why make a special case for it when string.find and S.find already exist
and are included expressly for that purpose?

-- 
 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