I want to implement a function to remove the punctuations, and I got the answer from a tutorial.
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
I am confused about the pattern=re.compile('[%s]' % re.escape(illegal_char))
part, I have no idea what the [%s]
means. Can anyone help me?