我想实现一个删除标点符号的功能,我从教程中得到了答案。
def filter_punctuation(words):
new_words = [];
illegal_char = string.punctuation
pattern=re.compile('[%s]' % re.escape(illegal_char))
for word in words:
new_word = pattern.sub(u'', word)
if not new_word == u'':
new_words.append(new_word)
return new_words
我对pattern=re.compile('[%s]' % re.escape(illegal_char))
部分感到困惑,不知道[%s]
是什么意思。谁能帮我?