On Mon, Sep 13, 2010 at 6:41 PM, Steven D'Aprano <st...@pearwood.info>wrote:
> On Tue, 14 Sep 2010 04:18:36 am Joel Goldstick wrote: > > > How about using str.split() to put words in a list, then run strip() > > over each word with the required characters to be removed ('`") > > > Doesn't work. strip() only removes characters at the beginning and end > of the word, not in the middle: > Exactly, you first split the words into a list of words, then strip each word > >>> "'I can't do this'".strip("'") > "I can't do this" > > If the aim is to remove all quotation marks, replace() is the right way > to go about it. It's not that hard either. > > text = text.replace("'", "").replace('"', "").replace("`", "") > > will remove all "standard" quotation marks, although if the source text > contains non-English or unusual unicode quotes, you will need to do > more work. > > Or if you prefer something more easily extendable to other characters: > > for c in "\"'`": > text = text.replace(c, "") > > > > -- > Steven D'Aprano > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Joel Goldstick
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor