def synonyms(word2nums, num2words, word):
 keys = word2nums[word]
 syns = set()
 for key in keys:
  syns = syns.union(num2words[key])
 if (word in syns):
  syns.remove(word)
 return sorted(syns)

def synonyms ( word2nums , num2words , word ) : keys = word2nums [ word ] syns = set ( ) for key in keys : syns = syns . union ( num2words [ key ] ) if ( word in syns ) : syns . remove ( word ) return sorted ( syns )
uses the word2nums and num2words dicts to look up synonyms for the given word .