Reputation:
I would like to know how to remove some punctuation symbol from the following list
string.punctuation
Out: '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
Specifically, I would like to remove @?&#!^_
to use it here:
def pr(text):
#1 Remove Punctuationa
nopunc = [char for char in text if char not in string.punctuation]
nopunc = ''.join(nopunc)
#2 Remove Stop Words
clean = [word for word in nopunc.split() if word.lower() not in stopwords.words('english')]
return clean
Thank you in advance for your answers and advice.
Upvotes: 2
Views: 155
Reputation: 7693
You can use re.sub
re.sub("[@?&#!^_]", "", string.punctuation)
'"$%\'()*+,-./:;<=>[\\]`{|}~'
Upvotes: 2
Reputation: 531325
The same way you are removing punctuation from the input string.
limited_punc = [char for char in string.punctuation if char in "@?&#!^_"]
nopunc = [char for char in text if char not in limited_punc]
Upvotes: 0