我想從文本文件中獲取標記(單詞)並將其從所有標點符號中除去。我嘗試以下:從Python中的文本中刪除標點符號
import re
with open('hw.txt') as f:
lines_after_254 = f.readlines()[254:]
sent = [word for line in lines_after_254 for word in line.lower().split()]
words = re.sub('[!#?,.:";]', '', sent)
我收到以下錯誤:
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or buffer
這至今仍保留着錯誤代更快! –
錯誤是'return _compile(pattern,flags).sub(repl,string,count)',這裏'sent'是一個列表! –