Skip to content
Related Articles

Related Articles

PyDictionary module in Python
  • Last Updated : 04 May, 2020

PyDictionary is a dictionary (as in the English language dictionary) module for Python2 and Python3. PyDictionary provides the following services for a word:

  • meanings
  • translations

Installation

To install PyDictionary run the following pip code on the terminal / command prompt:

pip install PyDictionary

Getting Started

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

from PyDictionary import PyDictionary

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

dict = PyDictionary()

To get the meaning of a word we need to pass the word in the meaning() method.



Example:




from PyDictionary import PyDictionary
  
  
dict = PyDictionary()
  
# meaning of "python"
meaning = dict.meaning("python")
print(meaning)

Output:

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

If a word is both a noun and a verb, then the method will return a dictionary containing the keys ‘Noun’ and ‘Verb’.

Example:




from PyDictionary import PyDictionary
  
  
dict = PyDictionary()
  
# meaning of "test"
meaning = dict.meaning("test")
print(meaning)

Output:

{‘Noun’: [‘trying something to find out about it’, ‘any standardized procedure for measuring sensitivity or memory or intelligence or aptitude or personality etc’, ‘a set of questions or exercises evaluating skill or knowledge’, ‘the act of undergoing testing’, ‘the act of testing something’, ‘a hard outer covering as of some amoebas and sea urchins’], ‘Verb’: [‘put to the test, as for its quality, or give experimental use to’, ‘test or examine for the presence of disease or infection’, “examine someone’s knowledge of something”, ‘show a certain characteristic when tested’, ‘achieve a certain score or rating on a test’, ‘determine the presence or properties of (a substance’, ‘undergo a test’]}

To get the translation of a word we need to pass the word in the translate() method as the first parameter and the language to be translated into as the second parameter. The name of the language should be in its respective language code.




from PyDictionary import PyDictionary
  
  
dict = PyDictionary()
  
# to translate into German
translation = dict.translate("happy",'de')
print(translation)

Output:

glücklich

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :