-1

I want to see if the word existing in the dictionary or not using the PyDictionary library. I have the following code but I can see some errors as “list index out of range” that I cannot understand. I am new to python.

def fst_wrd(exmp): 
    from PyDictionary import PyDictionary
    dictionary=PyDictionary()
 try: 
      var = (dictionary.meaning(exmp)) 
except: 
      if var == None: 
      return(False) 
else: 
      return (True) 
for exmp in my_list: 
      result = fst_wrd(exmp) 
      if result == True: 
        print(exmp, "is dict")
      else:
        print(exmp, "not dict")

Suppose I have a list as mylist=[“on", "carrot", "hello", "tunc"]. The error I am getting is list: index out of range.

  • Which line is producing the error? Please add the full stack trace. – 001 Jun 15 '21 at 17:01
  • 1
    Also, since indentation is important in Python you need to ensure your post has the same indentation as the original source code. – 001 Jun 15 '21 at 17:03
  • Does this answer your question? [Python how to get rid of PyDictionary error messages](https://stackoverflow.com/questions/52563826/python-how-to-get-rid-of-pydictionary-error-messages) – DarrylG Jun 15 '21 at 17:08

1 Answers1

1

Try using meaning(word, disable_errors=True) to disable the error message. You can try the following code:

def fst_wrd(exmp): 
    from PyDictionary import PyDictionary 
    dictionary = PyDictionary() 
    try: 
       var = dictionary.meaning(exmp, disable_errors=True) 
    except: 
       return False 
    else: 
       return True

blackbrandt
  • 2,010
  • 1
  • 15
  • 32