Efficient way of testing for substring being one of a set?

Jeff jeffober at gmail.com
Thu Apr 3 08:03:10 EDT 2008


def foo(sample, strings):
	for s in strings:
		if sample in s:
			return True
	return False

This was an order of magnitude faster for me than using str.find or
str.index.  That was finding rare words in the entire word-list (w/
duplicates) of War and Peace.



More information about the Python-list mailing list