How do I print out just the word itself in a WordNet synset using Python NLTK?

Solution 1:

If you want to do this without regular expressions, you can use a list comprehension.

[synset.name.split('.')[0] for synset in wn.synsets('dog') ]

What you're doing here is saying that, for each synset return the first word before the period.

Solution 2:

Try this:

for synset in wn.synsets('dog'):
    print synset.lemmas[0].name

You want to iterate over each synset for dog, and then print out the headword of the synset. Keep in mind that multiple words could attach to the same synset, so if you want to get all the words associated with all the synsets for dog, you could do:

for synset in wn.synsets('dog'):
    for lemma in synset.lemmas:
        print lemma.name

Solution 3:

aelfric5578 you're close: attribute name is a function, not a string.
[synset.name().split('.')[0] for synset in wn.synsets('dog') ]