Replace stop words (remove words from a string)

Casey Rodarmor casey at rodarmor.com
Thu Jan 17 03:48:35 EST 2008


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 <karthik3186 at gmail.com> wrote:
>
> How about -
>
> for s in stoplist:
>         string.replace(mystr, s, "")
>
> Hope this should work.
>
> -----Original Message-----
> From: python-list-bounces+karthik3186=gmail.com at python.org
> [mailto:python-list-bounces+karthik3186=gmail.com at python.org] On Behalf Of
> BerlinBrown
> Sent: Thursday, January 17, 2008 1:55 PM
> To: python-list at python.org
> Subject: Replace stop words (remove words from a string)
>
> 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 =
>
> kljsldkfjksjdfjsdjflkdjslkf[BAD]Kkjkkkkjkkjk[BAD]LSKJFKSFJKSJF;L[BAD2]kjsldf
> sd;
>
> if I have an array stop_list = [ "[BAD]", "[BAD2]" ]
>
> I want to replace the values in that list with a zero length string.
>
> I had this before, but I don't want to use this approach; I don't want
> to use the split.
>
> line_list = line.lower().split()
> res = list(set(keywords_list).difference(set(ENTITY_IGNORE_LIST)))
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080117/24057968/attachment-0001.html>


More information about the Python-list mailing list