I’m trying to complete ex36 (writing a text adventure game) and I am trying to use a thesaurus to allow a range of user inputs. I had a single function for this but I had to split this into functions for verbs, nouns and adjectives as the sets returned by the initial function were too vague and didn’t relate to the choice. Is there a way to cut these back down into one function? or at least shorten the code.
def Vthesaurus(word):
synonyms = []
for syn in wn.synsets(word, pos=wn.VERB):
for l in syn.lemmas():
synonyms.append(l.name())
return(set(synonyms))
def Nthesaurus(word):
synonyms = []
for syn in wn.synsets(word, pos=wn.NOUN):
for l in syn.lemmas():
synonyms.append(l.name())
return(set(synonyms))
def Athesaurus(word):
synonyms = []
for syn in wn.synsets(word, pos=wn.ADJ):
for l in syn.lemmas():
synonyms.append(l.name())
return(set(synonyms))