I would like to find words in WordNet that are at least 18 character long. I tried the following code:
from nltk.corpus import wordnet as wn
sorted(w for w in wn.synset().name() if len(w)>18)
I get the following error message:
sorted(w for w in wn.synset().name() if len(w)>18)
TypeError: synset() missing 1 required positional argument: 'name'
I am using Python 3.4.3.
How can I fix my code?
Use wn.all_lemma_names()
to get a list of all lemmas. I believe that's all the words you'll get out of Wordnet, so there should be no need to iterate over synsets (but you could call up the synsets for each lemma if you are so inclined).
You'll probably want to sort your hits by length:
longwords = [ n for n in wn.all_lemma_names() if len(n) > 18 ]
longwords.sort(key=len, reverse=True)