Substring Detection? Pythonically?
stephen at cerebralmaelstrom.com
Wed Oct 4 21:34:38 CEST 2000
Okay, say I have three different strings:
And a user gives me a string -- 'the', I want it to match to 'they'. Then
say they give me a string, 'to', I want it to match to 'tommy'. A string
of 'th' or 't' is ambiguious, and i want a list returned, ['they','that']
and ['they','that','tommy'] respectively.
What's the best way to do that? The onyl way I can think if is a massive
nested switch(if-elif), basically, since the 'words' i'm testing for will
be somewhat predefined. Another idea that just popped into my head was to
use mxTextTools instead of the nested-case, it'd do the same thing but it
seems like it'd be faster since Python isn't having to run through and
parse itself. Not sure tho :)
Note that my 'words' will end up being a rather big list, mebbe a hundred
at least, and i'll be checking against it very frequently, so want this to
be as efficient as possible.
More information about the Python-list