It seems like there should be a simpler way than:
import string s = \"string. With. Punctuation?\" # Sample string out = s.translate(string.maketrans(\"\",\
Here's one other easy way to do it using RegEx
import re punct = re.compile(r'(\w+)') sentence = 'This ! is : a # sample $ sentence.' # Text with punctuation tokenized = [m.group() for m in punct.finditer(sentence)] sentence = ' '.join(tokenized) print(sentence) 'This is a sample sentence'