Re: Replace stop words (remove words from a string)

2008-01-17 Thread bearophileHUGS
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

Re: Replace stop words (remove words from a string)

2008-01-17 Thread Bruno Desthuilliers
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 =

Re: Replace stop words (remove words from a string)

2008-01-17 Thread Gary Herron
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- >

Re: Replace stop words (remove words from a string)

2008-01-17 Thread Raymond Hettinger
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]kjsld­fsd; > if I have an array stop_list = [ "[BAD]", "[BAD2

Re: Replace stop words (remove words from a string)

2008-01-17 Thread Casey Rodarmor
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

Re: Replace stop words (remove words from a string)

2008-01-17 Thread Gary Herron
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

RE: Replace stop words (remove words from a string)

2008-01-17 Thread Karthik
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