I use this code for removing punctuation from sentence but Now I need to replace the punctuation with space
sentence = 'hi,how are you?'
temp = ''.join([''.join(c for c in s if c not in string.punctuation) for s in sentence])
outPut => `hihow are you`
I need to be like this
outPut => `hi how are you`
I need the fastest way to do that
>Solution :
You can tweak your generator comprehension, by using conditional expression:
import string
sentence = 'hi,how are you?'
temp = ''.join(c if c not in string.punctuation else ' ' for c in sentence)
print(temp) # hi how are you