我有一个句子列表,想要将每个句子中的标点符号移除。可以按照以下方式进行移除:
textList = ['This is bad.', 'You, me, him are going']
from string import punctuation
for text in textList:
for p in punctuation:
text = text.replace(p,'')
print(text)
但是我想修改列表内容并将其放在一行中。就像这样:
# obviously this does not work
textList = [(text.replace(p,'') for p in punctuation) for text in textList]
什么是正确的做法?