The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Create a CLI dictionary lookup

Here’s a simple Python script for a CLI dictionary lookup tool. It uses an online dictionary API (Free Dictionary API) to fetch word meanings, definitions, examples, and synonyms.

python
import requests import sys def lookup_word(word): url = f"https://api.dictionaryapi.dev/api/v2/entries/en/{word}" response = requests.get(url) if response.status_code != 200: print(f"No definitions found for '{word}'.") return data = response.json() for entry in data: print(f"Word: {entry.get('word')}") meanings = entry.get('meanings', []) for meaning in meanings: part_of_speech = meaning.get('partOfSpeech', 'N/A') print(f"nPart of Speech: {part_of_speech}") definitions = meaning.get('definitions', []) for i, definition in enumerate(definitions, 1): print(f" Definition {i}: {definition.get('definition')}") example = definition.get('example') if example: print(f" Example: {example}") synonyms = definition.get('synonyms', []) if synonyms: print(f" Synonyms: {', '.join(synonyms)}") print("n" + "-"*50 + "n") def main(): if len(sys.argv) < 2: print("Usage: python dict_lookup.py <word>") return word = sys.argv[1] lookup_word(word) if __name__ == "__main__": main()

How to use:

  1. Save this as dict_lookup.py.

  2. Run in the terminal:

    arduino
    python dict_lookup.py <word>

    Replace <word> with the word you want to look up.


If you want, I can help you build a version that works offline or includes additional features like pronunciation or multiple languages.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About