How to get a list of antonyms using TextBlob?
The TextBlob library uses the NLTK library's WordNet interface, this will provide definitions, synonyms and antonyms of specific word.
Getting Antonyms using TextBlob
from textblob import TextBlob from textblob import Word text_word = Word('safe') antonyms = set() for synset in text_word.synsets: for lemma in synset.lemmas(): if lemma.antonyms(): antonyms.add(lemma.antonyms()[0].name()) print(antonyms)
{'dangerous', 'out'}
2019-05-28T01:50:29+05:30
2019-05-28T01:50:29+05:30
Amit Arora
Amit Arora
Python Programming Tutorial
Python
Practical Solution