drop punctuation python code example
Example 1: remove punctuations using python
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
my_str = "Hello!!!, he said ---and went."
no_punct = ""
for char in my_str:
if char not in punctuations:
no_punct = no_punct + char
print(no_punct)
Example 2: python remove punctuation from text file
import string
sentence = "Hey guys !, How are 'you' ?"
no_punc_txt = ""
for char in sentence:
if char not in string.punctuation:
no_punc_txt = no_punc_txt + char
print(no_punc_txt);
no_punc_txt = sentence.translate(sentence.maketrans('', '', string.punctuation))
print(no_punc_txt);