Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

remove punctuation from string python

#with re
import re
s = "string. With. Punctuation?"
s = re.sub(r'[^ws]','',s)
#without re
s = "string. With. Punctuation?"
s.translate(str.maketrans('', '', string.punctuation))
Comment

Removing punctuation in Python

import string 
from nltk.tokenize import word_tokenize
s =  set(string.punctuation)          # !"#$%&'()*+,-./:;<=>?@[]^_`{|}~
sentence = "Hey guys !, How are 'you' ?"
sentence = word_tokenize(sentence)
filtered_word = []
for i in sentence:
    if i not in s:
        filtered_word.append(i);
for word in filtered_word:
  print(word,end = " ")
Comment

clean punctuation from string python

s.translate(str.maketrans('', '', string.punctuation))
Comment

remove punctuation python string library

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);                 # Hey guys  How are you 
# or:
no_punc_txt = sentence.translate(sentence.maketrans('', '', string.punctuation))
print(no_punc_txt);                 # Hey guys  How are you 
Comment

Python remove punctuation from a string

# Python program to remove punctuation from a string

import string
text= 'Hello, W_orl$d#!'

# Using translate method
print(text.translate(str.maketrans('', '', string.punctuation)))
Comment

function to remove punctuation in python

import string

def remove_punctuation(text):
    '''a function for removing punctuation'''
    # replacing the punctuations with no space, 
    # which in effect deletes the punctuation marks 
    translator = str.maketrans('', '', string.punctuation)
    # return the text stripped of punctuation marks
    return text.translate(translator)
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 :: stack in python using linked list 
Python :: python pickle module 
Python :: python find index of closest value in list 
Python :: round to nearest multiple of 5 python 
Python :: replace nan 
Python :: np ignore divide by zero seterr 
Python :: matplotlib: use colormaps for line plot colors 
Python :: strip characters from a string python 
Python :: python list index() 
Python :: video steganography using python 
Python :: create requirements file and load it in new envirnment. 
Python :: check word in list 
Python :: ip address finder script python 
Python :: python is prime 
Python :: django save object in view 
Python :: python fiboncci 
Python :: tqdm 2 progress bars 
Python :: get unique words from pandas dataframe 
Python :: python object name 
Python :: python if not 
Python :: find the place of element in list python 
Python :: change list item in python 
Python :: python dict if key does not exist 
Python :: pytorch multiply tensors element by elementwise 
Python :: example of break statement in python 
Python :: python split at index 
Python :: python single line comment 
Python :: add two strings together 
Python :: prevent selenium from closing 
Python :: create 2d array with rows and columns 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =