PyDictionary module in Python

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

glücklich



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.