What algorithm does Python use to evaluate: if substring in string

Tor Erik torerik81 at gmail.com
Sat Sep 9 10:10:03 EDT 2006


I would be surprised if it is the naive:

m = 0
s1 = "me"
s2 = "locate me"
s1len = len(s1)
s2len = len(s2)
found = False

while m + s1len <= s2len:
	if s1 == s2len[m:m+s1len]:
		found = True
		break
	m += 1



More information about the Python-list mailing list