from nltk.corpus import wordnet
f = open('wordnet_wordlist.txt', 'w')
for syn in list(wordnet.all_synsets()):
    f.write(syn.name[:-5])
f.write('\n')
f.close()
f = open('wordnet_wordlist.txt')
f2 = open('wordnet_wordlist_final.txt', 'w')
uniquelines = set(f.read().split('\n'))
f2.write(''.join([(line + '\n') for line in uniquelines]))
f2.close()
Finding words from Wordnet separated by a fixed Edit Distance from a given word