That's much better than what I was about to post:<br><br>for s in stoplist:<br> string.join(mystr.split(s, ""))<br><br>Berlin: Why are you keen on avoiding split()?<br><br><div><span class="gmail_quote">On 1/17/08,
<b class="gmail_sendername">Karthik</b> <<a href="mailto:karthik3186@gmail.com">karthik3186@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
How about -<br><br>for s in stoplist:<br> string.replace(mystr, s, "")<br><br>Hope this should work.<br><br>-----Original Message-----<br>From: python-list-bounces+karthik3186=<a href="mailto:gmail.com@python.org">
gmail.com@python.org</a><br>[mailto:<a href="mailto:python-list-bounces+karthik3186=gmail.com@python.org">python-list-bounces+karthik3186=gmail.com@python.org</a>] On Behalf Of<br>BerlinBrown<br>Sent: Thursday, January 17, 2008 1:55 PM
<br>To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>Subject: Replace stop words (remove words from a string)<br><br>if I have an array of "stop" words, and I want to replace those values
<br>with something else; in a string, how would I go about doing this. I<br>have this code that splits the string and then does a difference but I<br>think there is an easier approach:<br><br>E.g.<br><br>mystr =<br>kljsldkfjksjdfjsdjflkdjslkf[BAD]Kkjkkkkjkkjk[BAD]LSKJFKSFJKSJF;L[BAD2]kjsldf
<br>sd;<br><br>if I have an array stop_list = [ "[BAD]", "[BAD2]" ]<br><br>I want to replace the values in that list with a zero length string.<br><br>I had this before, but I don't want to use this approach; I don't want
<br>to use the split.<br><br>line_list = line.lower().split()<br>res = list(set(keywords_list).difference(set(ENTITY_IGNORE_LIST)))<br><br><br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list
</a><br><br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a><br></blockquote></div><br>