I'm having troubles with the loop. I need it to print 'synonyms' just once if any of the lemmas of that sense match with word2, otherwise 'not synonyms', but only once.
from nltk.corpus import wordnet as wn
word1 = 'motorcar'
word2 = 'automobile'
for syn in wn.synsets(word1):
for lemma in syn.lemma_names():
if lemma == word2 and lemma != word1:
print('Synonyms')
elif all(syn.lemma_names()) != word2:
print('not synonyms')
The usual pattern is to initialize a variable outside the loop, then report the result at the end of the loop. Something like this: