[Tutor] Searching for a substring within a list
Scot Stevenson
scot@possum.in-berlin.de
Tue Mar 11 04:52:01 2003
Hello Magnus,
My apologies if this has already been pointed out, I didn't see it:
> For detecting substrings, the normal python idiom is:
>
> bigString = "sldkfkjhgksdhfksdhf"
> subString = "ks"
>
> if bigString.find(subString) != -1:
> print "I found", subString, "in", bigString
Which I always thought was terribly counterintuitive (waddaya mean, "-1"? ). I
remember trying
if subString in bigString:
print "I found", subString, "in", bigString
which _doesn't_ work, much to my surprise; only single character substrings
are found this way.
However, I have been told that this will change in a future release, thereby
bringing even more clarity to the language, and we can do away with this
strange "-1" stuff.
Y, Scot
--
Verbing weirds language
Scot W. Stevenson - Zepernick, Germany