You could also just do this:
words_stripped = ''.join(c for c in s if not c in string.punctuation)
Disclaimer: The code below is using Python 2 syntax in an IPython shell - the string.translate
function seems to have changed in Python 3 - your above solution was for Python 2.
Addressing timing as mentioned by @Chris_Rands in the comment to this answer:
In [17]: %timeit s.translate(None, string.punctuation)
100000 loops, best of 3: 15.6 µs per loop
In [18]: %timeit ''.join(c for c in s if not c in string.punctuation)
1000 loops, best of 3: 1.04 ms per loop
In [19]: %timeit ''.join(c for c in s if not c in punctuation_set)
1000 loops, best of 3: 632 µs per loop
This was done with s
set to a 5 paragraphs generated here: https://www.lipsum.com/feed/html
So, yes, the translate method is by far the fastest. At the same time... depending on how many times you need to do this, you don't really need to worry about this.
Use the simplest approach you can think of and then use a profiling tool (CProfiler) to figure out where exactly your bottleneck is if your script isn't fast enough.