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

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

PREVIOUS NEXT
Code Example
Python :: django.db.utils.ProgrammingError: relation "users" does not exist in django 3.0 
Python :: streamlit python install 
Python :: python 2 is no longer supported 
Python :: NumPy unique Syntax 
Python :: found features with object datatype 
Python :: pip install qrcode python 
Python :: check if a the time is 24 hours older python 
Python :: set seed tensorflow 
Python :: split a variable into multiple variables in python 
Python :: matplotlib location legend 
Python :: append in a for loop python 
Python :: how explode by using two columns pandas 
Python :: error handling in python using flask 
Python :: python operators 
Python :: random numbers python 
Python :: django save vs create 
Python :: Module "django.contrib.auth.hashers" does not define a "BcryptPasswordHasher" attribute/class 
Python :: change text in legend matplotlib 
Python :: pil normalize image 
Python :: how to convert utf-16 file to utf-8 in python 
Python :: calculate the distance between two points 
Python :: python string slicing 
Python :: ImportError: /home/user/.local/lib/python3.8/site-packages/pytorch3d/_C.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZN2at5zerosEN3c108ArrayRefIlEENS0_13TensorOptionsE 
Python :: openpyxl fast tutorial 
Python :: how to change python version 
Python :: python find in list 
Python :: python epoch to datetime 
Python :: color python 
Python :: pandas make new dataframe 
Python :: python regex 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =