[CentralOH] Removing Punctuation
pybokeh
pybokeh at gmail.com
Tue Jan 21 00:47:39 CET 2014
Wow, I just realized there is a difference in str.translate() method between
Python 2 and Python 3. I'm currently a Python 3 user and
str.translate(string.punctuation)
does not work for me (NOTE-str.translate() takes only 1 argument in
Python 3).
So when I execute str.translate(string.punctuation), it does not get rid
of the punctuation
marks since it no longer knows to map or delete the punctuation marks.
Hmm, now I wonder how do I use the str.translate() method in Python 3 to
get rid of the
punctuation marks?
On 01/20/2014 05:56 PM, jep200404 at columbus.rr.com wrote:
> On Mon, 20 Jan 2014 16:09:56 -0500, jep200404 at columbus.rr.com wrote:
>
>> [1] See http://colug.net/python/dojo/20140117/word-count-example-rev2.ipynb
> "for character in bunch_of_words:\n",
> " if character in string.punctuation:\n",
> " bunch_of_words = bunch_of_words.replace(character,\"\")\n",
>
> can be simplified as .translate(None, string.punctuation)
>
> as in http://colug.net/python/dojo/20140117/word-count-example-rev3.ipynb
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh
More information about the CentralOH
mailing list