Raymond Hettinger:
> Regular expressions should do the trick.
> >>> stoppattern = '|'.join(map(re.escape, stoplist))
> >>> re.sub(stoppattern, '', mystr)
If the stop words are many (and similar) then that RE can be optimized
with a trie-based strategy, like this one called "List":
http://search.cp
BerlinBrown a écrit :
> if I have an array of "stop" words, and I want to replace those values
> with something else; in a string, how would I go about doing this. I
> have this code that splits the string and then does a difference but I
> think there is an easier approach:
>
> E.g.
>
> mystr =
Karthik wrote:
> How about -
>
> for s in stoplist:
> string.replace(mystr, s, "")
>
That will work, but the string module is long outdated. Better to use
string methods:
for s in stoplist:
mystr.replace(s, "")
Gary Herron
> Hope this should work.
>
> -Original Message-
>
On Jan 17, 12:25 am, BerlinBrown <[EMAIL PROTECTED]> wrote:
> if I have an array of "stop" words, and I want to replace those values
> with something else;
> mystr =
> kljsldkfjksjdfjsdjflkdjslkf[BAD]Kkjjkkjk[BAD]LSKJFKSFJKSJF;L[BAD2]kjsldfsd;
> if I have an array stop_list = [ "[BAD]", "[BAD2
That's much better than what I was about to post:
for s in stoplist:
string.join(mystr.split(s, ""))
Berlin: Why are you keen on avoiding split()?
On 1/17/08, Karthik <[EMAIL PROTECTED]> wrote:
>
> How about -
>
> for s in stoplist:
> string.replace(mystr, s, "")
>
> Hope this should
BerlinBrown wrote:
> if I have an array of "stop" words, and I want to replace those values
> with something else; in a string, how would I go about doing this. I
> have this code that splits the string and then does a difference but I
> think there is an easier approach:
>
> E.g.
>
> mystr =
> kl
How about -
for s in stoplist:
string.replace(mystr, s, "")
Hope this should work.
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
BerlinBrown
Sent: Thursday, January 17, 2008 1:55 PM
To: python-list@python.org
Subject: Replace stop words (remov