Link to home
Start Free TrialLog in
Avatar of sebastizz
sebastizz

asked on

TypeError: 'list' object is not callable in python

Im trying to run the following code in python

from nltk.corpus import wordnet as wn
for i in wn.all_synsets():
    if i.pos() in ['a', 's']: # If synset is adj or satelite-adj.
        for j in i.lemmas(): # Iterating through lemmas for each synset.
            if j.antonyms(): # If adj has antonym.
                # Prints the adj-antonym pair.
                print j.name(), j.antonyms()[0].name()

Open in new window

This should give me a complete list of opposite words from wordnet. Unfortunately instead of this i get this error:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
TypeError: 'list' object is not callable

What am I doing wrong?
SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sebastizz
sebastizz

ASKER

HI.

OK tried that and also getting rid of the () after lemmas so that the code now looks like:

from nltk.corpus import wordnet as wn
for i in wn.all_synsets():
    if i.pos in ['a', 's']:
        for j in i.lemmas:
            if j.antonyms():
                print j.name(), j.antonyms()[0].name()

but now I get the error:

Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
TypeError: 'str' object is not callable

Any ideas?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Don't I get any credit for my "drop the parentheses" comment?
Good answer