How to Create a Dictionary Using Python
The dictionary asks the user to input a word and as a result provides the defintion and what part of speech it is.
copy paste the code below and run it in order to install PyDictionary:
pip install PyDictionary
Once You have run the code above, run this code:
from PyDictionary import PyDictionary
# Initialize the PyDictionary
dictionary = PyDictionary()
# Function to fetch the meaning of a word
def fetch_meaning(word):
try:
meanings = dictionary.meaning(word)
if meanings:
for part_of_speech, definition_list in meanings.items():
print(f"{part_of_speech}:")
for definition in definition_list:
print(f" - {definition}")
else:
print(f"Meaning not found for '{word}'")
except Exception as e:
print(f"An error occurred: {e}")
# Simple CLI interface for word lookup
while True:
user_input = input("Enter a word to lookup (or 'exit' to quit): ").strip()
if user_input.lower() == 'exit':
break
fetch_meaning(user_input)