[CentralOH] Removing Punctuation
pybokeh
pybokeh at gmail.com
Tue Jan 21 03:24:50 CET 2014
Thanks for this.
I thought I could replace a punctuation mark with a single white space
by doing this:
S.translate(S.maketrans(" ", " ", string.punctuation))
But that didn't work. Any ideas how to replace a punctuation mark with
a single white space?
The reason being, what if there is no space after a punctuation mark or
three periods were used:
"Mary had a little lamb...little lamb...little lamb! Do you know what
Mary's problem is?No I do not!"
Then "isNo" ends up being counted as a word and also "lamblittle", so I
want to prevent this by
replacing a punctuation mark with a singe white space instead of no
white space.
On 01/20/2014 07:20 PM, Eric Floehr wrote:
>
> Hmm, now I wonder how do I use the str.translate() method in
> Python 3 to get rid of the
> punctuation marks?
>
>
>
> >>> import string
> >>> S = "Some, string! With punctuation."
> >>> S.translate(S.maketrans("", "", string.punctuation))
> 'Some string With punctuation'
>
> http://docs.python.org/3/library/stdtypes.html#str.maketrans
>
>
>
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20140120/855d75cb/attachment.html>
More information about the CentralOH
mailing list