Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

# remove punctuation

# remove punctuation
import string
string.punctuation

#!"#$%&'()*+,-./:;<=>?@[]^_`{|}~

my_text = "The well-known story I told at the conferences [about hypocondria] in Boston, New York, Philadelphia,...and Richmond went as follows"
remove_punc=my_text.translate(str.maketrans('', '', string.punctuation))
print(remove_punc)


#The wellknown story I told at the conferences about hypocondria in Boston New York Philadelphiaand Richmond went as follows
Comment

remove punctuation

# define punctuation
punctuations = '''!()-[]{};:'",<>./?@#$%^&*_~'''

my_str = "Hello!!!, he said ---and went."

# To take input from the user
# my_str = input("Enter a string: ")

# remove punctuation from the string
no_punct = ""
for char in my_str:
   if char not in punctuations:
       no_punct = no_punct + char

# display the unpunctuated string
print(no_punct)
Comment

Remove Punctuation from a String

import string
 
test_str = 'Gfg, is best: for ! Geeks ;'
 
test_str = test_str.translate
    (str.maketrans('', '', string.punctuation))
print(test_str)
Comment

PREVIOUS NEXT
Code Example
Python :: python sys.argv 
Python :: python open google 
Python :: numpy.sign() in Python 
Python :: pandas rename 
Python :: readlines replace  
Python :: delete occurrences of an element if it occurs more than n times python 
Python :: how to make a nice login django form 
Python :: python string cut left 
Python :: live server python 
Python :: read specific columns from csv in python pandas 
Python :: how to write to a specific line in a file python 
Python :: python max function recursive 
Python :: ordered dictionary 
Python :: how to iterate over a list in python 
Python :: adding one element in dictionary python 
Python :: drop na pandas 
Python :: tk inter entry 
Python :: list get every 2nd element 
Python :: python change directory to previous 
Python :: turtle with python 
Python :: python casting 
Python :: not equal python 
Python :: Hungry Chef codechef solution 
Python :: python open directory and read files 
Python :: add values of two columns pandas 
Python :: dropna pandas 
Python :: django create superuser from script 
Python :: python if string contains char 
Python :: vscode python workding directory 
Python :: tkinter frameless window 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =