[CentralOH] Removing Punctuation with str.translate() in Python 3

jep200404 at columbus.rr.com jep200404 at columbus.rr.com
Tue Jan 21 01:36:02 CET 2014


On Mon, 20 Jan 2014 18:47:39 -0500, pybokeh <pybokeh at gmail.com> wrote:

> ... now I wonder how do I use the str.translate() method in 
> Python 3 to get rid of the punctuation marks?

Careful reading[1] suggests an answer.
Use str.maketrans() and str.translate().
Use the third argument of maketrans to create a 
translation table to convert punctuation to None.
str.translate() converts punctuation to None, and deletes them.

[1] http://docs.python.org/3/library/stdtypes.html#str.translate
    http://docs.python.org/3/library/stdtypes.html#str.maketrans


More information about the CentralOH mailing list