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

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 list of strings python

import string
words = ["hell'o", "Hi,", "bye bye", "good bye", ""]
words = [''.join(letter for letter in word if letter not in string.punctuation) for word in words if word]
print(words)
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 :: dataframe add row 
Python :: python create env ubuntu 
Python :: python 2 deprecated 
Python :: how to convert to string in python 
Python :: get columns by type pandas 
Python :: python library to make qr codes 
Python :: creating base models django 
Python :: rotate point around point python 
Python :: lexicographic order python 
Python :: matplotlib position legend 
Python :: prime number in python 
Python :: python package version 
Python :: error handling flask 
Python :: remove extra spaces and empty lines from string python 
Python :: convert a pdf folder to excell pandas 
Python :: python ftplib get list of directories 
Python :: How to perform Bubble sort in Python? 
Python :: how to use csv in python 
Python :: pygame how to find the full screen mode 
Python :: turn false true column into 0 1 pandas 
Python :: Double-Linked List Python 
Python :: tasks discord py 
Python :: dataframe standardise 
Python :: openpyxl create new file 
Python :: django ModelChoiceField value not id 
Python :: python infinity 
Python :: end python program 
Python :: get value and key from dict python 
Python :: python sum array 
Python :: how to write the character from its ascii value in python 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =