【发布时间】:2014-04-29 21:13:11
【问题描述】:
我已经从报纸上捕获了标题,我也从标题中删除了停用词,但在删除停用词后,这个词带有单引号,所以我不想要这些引号,为此我尝试了以下代码:
from nltk.corpus import stopwords
blog_posts=[]
stop = stopwords.words('english')+[
'.',
',',
'--',
'\'s',
'?',
')',
'(',
':',
'\'',
'\'re',
'"',
'-',
'}',
'{',
u'—',
'a', 'able', 'about', 'above', 'according', 'accordingly', 'across', 'actually', 'after', 'afterwards', 'again', 'against', 'all', 'allow', 'allows', 'almost', 'alone', 'along', 'already', 'also', 'although', 'always', 'am', 'among', 'amongst', 'an', 'and', 'another', 'any', 'anybody',
]
file=open("resources/ch05-webpages/newspapers/TOI2232014.csv","r+")
t=[i for i in file.read().split() if i not in stop]
blog_posts.append((t,))
print blog_posts
所以这段代码的输出是:
[(['"\'Duplicates\'', 'BJP,', 'Jaswant', 'Singh', 'says"', '"Flight'],)]
但我想要这样的输出:
[([Duplicates,BJP,Jaswant,Singh,ays,Flight])]
那么我可以为这个输出做些什么呢?
【问题讨论】:
标签: python-2.7 nltk stop-words