Open In App

PyDictionary module in Python

Last Updated : 05 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

AyDictionary

It’s a Python module used to fetch definitions of words, while googletrans provides translation services.

  • meanings
  • translations

Installation

To install AyDictionary run the following

pip

code on the terminal / command prompt:

pip install AyDictionary googletrans==4.0.0-rc1

Getting Started

Now let us see how to use the AyDictionary module. First of all we need to import the module:

from AyDictionary import AyDictionary

After importing the module, we need to create an instance of it in order to use it:

dictionary = AyDictionary()

To get the meaning of a word we need to pass the word in the

meaning() method

Example

Python
# Get the meaning of "python"
meaning = dictionary.meaning("python")
print(f"Meaning of 'python':")
print(meaning)


Output:

Meaning of 'python':
{'Noun': ['large Old World boas', 'a soothsaying spirit or a person who is possessed by such a spirit', '(Greek mythology']}


Using googletrans

googletrans provides translations of words into different languages.

Import the Module

Python
from googletrans import Translator


Create a Translator Instance

Python
translator = Translator()


Translate a Word

Use the translate() method to get translations.

Python
# Translate "happy" to German
translation = translator.translate("happy", dest="de")
print(f"\nTranslation of 'happy' to German:")
print(translation.text)

Output:

glücklich






Next Article
Article Tags :
Practice Tags :

Similar Reads