"str.contains(part)" or alternatives?
tjreedy at udel.edu
Thu Sep 12 15:26:10 CEST 2002
"Joseph A. Knapka" <jknapka at earthlink.net> wrote in message
news:mailman.1031804415.15646.python-list at python.org...
> Ah. So we have:
> not(X in Y <==> X in [Z for Z in Y])
> But only if Y is a string. That strikes me as a trifle odd,
> but nevertheless I agree that the "substring in string"
> behavior seems more useful.
As Tim said, this was debated on the dev list. In the end, Guido
decided that giving 'in' slightly expanded semantics for strings and
strings only, though not 'pure', seemed very natural and practical and
no wierder than some other type-specific differences for other
operators. While strings are sequences, they are different in that
they are *not* recursive, unlike tuples and lists. A string of len>1
can be a substring of a string but it cannot be a 'member' of the
string. On the other hand, [1,2,3] is both a sublist and item of
[1,2,3,[1,2,3]]. So "[1,2,3] in alist" would be ambiguious unless
restricted to one meaning or the other.
Terry J. Reedy
More information about the Python-list