检查单词时不了解类型错误的原因



我需要检查一个列表中的单词是否存在于pdf文件中,但是我有一些错误TypeError: argument of type 'spacy.tokens.token.Token' is not iterable的问题,我不明白我该如何修复它。

word_list = ['Education', 'Skills']    
for word in word_list:
lst = []
for sentence in words:
if word in sentence: 
lst.append(word)
print('{0} key word(s) in sentence: {1}'.format(len(lst), ', '.join(lst)))
print(sentence + "n")

我想你的意思是:

word_list = ['Education', 'Skills']    
lst = []
for word in word_list:
if word in sentence: 
lst.append(word)
if len(last) > 0:
print('{0} key word(s) in sentence: {1}'.format(len(lst), ', '.join(lst)))
print(sentence + "n")

,其中sentence是字符串。我想你可能在使用words时打错了,它之前被定义为空格标记,导致了这个令人困惑的错误消息。

相关内容

最新更新