为什么在实现`wordnet.synsets()时会出现属性错误?

问题描述 投票:-1回答:1

我试图在list中找到单词的某些同义词。这是我的代码:

test=['work','goat',...]
lst=[]

for i in range(len(test)):

    for s in wordnet.synsets(test[i]):
        for j in s.lemmas():
            lst.append(j.name()) 

但是我收到此错误:AttributeError: 'generator' object has no attribute 'lower'for s in wordnet.synsets(test[i])。请帮助我。

python wordnet
1个回答
0
投票

我假设您的...列表中的省略号(test)可能有问题此代码对我有用(Win10上的python 3.8.2):

from nltk.corpus import wordnet

test = ['work','goat']
lst = []

for word in test:
    for s in wordnet.synsets(word):
        for j in s.lemmas():
            lst.append(j.name())
© www.soinside.com 2019 - 2024. All rights reserved.