Substring Detection? Pythonically?
insyte at petra.squad51.net
insyte at petra.squad51.net
Wed Oct 4 15:49:55 EDT 2000
In article <20001004.123529.97857 at Jeremy.cerebralmaelstrom.com>, Stephen
Hansen wrote:
>Okay, say I have three different strings:
> #1: they
> #2: that
> #3: tommy
>
>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.
I'm just flailing around here, but it doesn't seem too tough to me. How
'bout something like this:
----------
import re
bloop = 'to'
blah = ['they', 'that', 'tommy']
blecch = []
for blargh in blah:
if re.match(bloop, blargh):
blecch.append(blargh)
print blecch
----------
Sound viable?
--
Ben Beuchler insyte at bitstream.net
MAILER-DAEMON (612) 321-9290 x101
Bitstream Underground www.bitstream.net
More information about the Python-list
mailing list