I would like to replace (and not remove) all punctuation characters by \" \" in a string in Python.
Is there something efficient of the following flavo
This workaround works in python 3:
import string ex_str = 'SFDF-OIU .df !hello.dfasf sad - - d-f - sd' #because len(string.punctuation) = 32 table = str.maketrans(string.punctuation,' '*32) res = ex_str.translate(table) # res = 'SFDF OIU df hello dfasf sad d f sd'