Создаешь пустой список, перебираешь существующий, добавляешь в пустой, если встречается знак препинания пропускаешь.
import string
def remove_punctuation(text):
return ''.join(char for char in text if char not in string.punctuation)
sample_text = "Hello, World! How are you? This is a test, with some punctuation."
print(remove_punctuation(sample_text))
import string
def remove_punctuation(text):
return text.translate(str.maketrans('', '', string.punctuation))
sample_text = "Hello, World! How are you? This is a test, with some punctuation."
print(remove_punctuation(sample_text))
text.lower()
punctuation = [".", ",", "!", "?"]
пробовала так:
for i in punctuation:
text.replace(i, " ")
и так:
for i in punctuation:
a = " "
text.replace(i, a)
не работает.
Помогите пожалуйста!