【发布时间】:2013-06-05 06:33:35
【问题描述】:
我是一名 Python 新手,试图使用特定单词的字典来计算语料库(语料库)中出现的单词数。语料库是一种经过标记化、规范化、词形还原和词干化的字符串类型。
dict = {}
dict ['words'] = ('believe', 'tried', 'trust', 'experience')
counter=0
Result = []
for word in corpora:
if word in dict.values():
counter = i + 1
else counter = 0
此代码在 dict.values() 行产生语法错误。任何帮助表示赞赏!
【问题讨论】:
-
else后面少了一个冒号,它位于错误的缩进块上 -
离题:不要使用
dict作为变量名。 -
这可能会对您有所帮助,“语料库”的价值是什么。 >>> dict = {} >>> dict ['words'] = ('believe', 'tried', 'trust', 'experience') >>> dict.values() [('believe', 'tried ', '信任', '经验')]
标签: python for-loop dictionary counting words