既然是一次性去掉所有的标点符号,那当然是用正则表达式啦:
import re
punctuation = '!,;:?"\''
def removePunctuation(text):
text = re.sub(r'[{}]+'.format(punctuation),'',text)
return text.strip().lower()
text = " Hello, world! "
print removePunctuation(text)
既然是一次性去掉所有的标点符号,那当然是用正则表达式啦:
import re
punctuation = '!,;:?"\''
def removePunctuation(text):
text = re.sub(r'[{}]+'.format(punctuation),'',text)
return text.strip().lower()
text = " Hello, world! "
print removePunctuation(text)