I’m using Python v2.6 and I have a string which contains a number of punctuation characters I’d like to strip out. Now I’ve looked at using the string.punctuation() function but unfortunately, I want to strip out all punctuation characters except fullstops and dashes. In total, there are only a total of 5 punctuation marks I’d like to strip out – ()\"'
Any suggestions? I’d like this to be the most efficient way.
Thanks
You can use
str.translate(table[, deletechars])withtableset toNone, which will result in all characters fromdeletecharsbeing removed from the string:Some examples: