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

python3 strip punctuation from string

import string
#make translator object
translator=str.maketrans('','',string.punctuation)
string_name=string_name.translate(translator)
Comment

python remove punctuation

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

PREVIOUS NEXT
Code Example
Python :: replace string if it contains a substring pandas 
Python :: pip install streamlit 
Python :: python allowed variable caracters 
Python :: get instance of object python 
Python :: import math sqrt python 
Python :: qrcode.make python 
Python :: python get file path 
Python :: How to scale a pandas dataframe 
Python :: import excel python 
Python :: python open file from explorer 
Python :: how to add rows to empty dataframe 
Python :: python get last element of list 
Python :: 1. write a program to multiply two numbers using function python 
Python :: pandas dataframe unique multiple columns 
Python :: how to run linux command in python 
Python :: how to clear ipython console 
Python :: read file into list python 
Python :: readlines from file python 
Python :: matplotlib to pdf 
Python :: appending to a file in python 
Python :: sympy function definition 
Python :: how to import sin and cos in python 
Python :: select rows from a list of indices pandas 
Python :: search dictionary for value 
Python :: python date to timestamp 
Python :: sort a list of array python 
Python :: radix sort in python 
Python :: how to get colored text in python 
Python :: pandas group by day 
Python :: concat columns pandas dataframe 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =