PyDictionary - A  "REAL" Python Dictionary

PyDictionary - A "REAL" Python Dictionary

Table of contents

No heading

No headings in the article.

One of the features of python which has made it popular is its functionality of various libraries, packages, and modules. A dictionary is a listing of lexemes from the lexicon of one or more specific languages, often arranged alphabetically, which may include information on definitions, usage, etymologies, pronunciations, translation, etc. Other than the dictionary which is a collection in python, there exists a real dictionary which is a module called PyDictionary. This module uses Python Requests, BeautifulSoup4, and goslate as dependencies.

Python’s PyDictionary module/package can be used for getting the meaning, translation, synonym, and antonyms of words in the English language. PyDictionary is a Module while Dictionary is just an Object Type.

How PyDictionary Module works

Functions inside PyDictionary make API requests to different websites passing English Word as the parameter.

  • For getting the meaning of a word PyDictionary send an API request to wordnet.princeton.edu which is a database of words and their meanings, this is developed by Princeton University.

  • For doing translation of English Words to other languages, PyDictionary send an API request to Google’s Translator and show whatever is returned by it.

  • For getting synonyms/antonyms of a Word, PyDictionary send an API request to synonyms.com which is a database of words and their respective synonyms or antonyms.

The first thing to do before using any python package is to install, using the pip command. We install PyDictionary by typing - pip install PyDictionary in the terminal

Testing its functionalities

from PyDictionary import PyDictionary
dictionary=PyDictionary()

This will create a local instance of the PyDictionary class and now it can be used to get meanings, translations, etc.

print (dictionary.meaning("code"))

This will return a dictionary containing the meanings of the word.

For Synonyms,

print (dictionary.synonym("behind"))

This will return a list containing the Synonyms of the word.

For Antonyms,

print (dictionary.antonym("outside"))

This will return a list containing the Antonyms of the word.

For Translations,

print(dictionary.translate(“book”,”fr”)

This will translate the word into the language specified which is French.

Just like python dictionary which stores data in key: value pair, Pydictionary also represents data items as keys and values, for each word meaning, the part of speech such as noun, verb, adjective are the KEYS while VALUES represent the real meaning of words.