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

pybokeh pybokeh at gmail.com
Tue Jan 21 02:43:20 CET 2014


Oh wow, this makes readability or clarity worse in my opinion.

Surely there is a performance gain from using translate()/maketrans() 
combination?

Maybe profiling a Python program can be a topic for discussion at the 
next Python
dojo meeting :-)

On 01/20/2014 07:36 PM, jep200404 at columbus.rr.com wrote:
> 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
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh



More information about the CentralOH mailing list