How to check if a word is an English word with Python?

Sometimes, we want to check if a word is an English word with Python.

In this article, we’ll look at how to check if a word is an English word with Python.

How to check if a word is an English word with Python?

To check if a word is an English word with Python, we can use the enchant module.

To install it, we run:

pip install pyenchant

Then we can use it by writing:

import enchant

d = enchant.Dict("en_US")
print(d.check("Hello"))
print(d.suggest("Helo"))

We return the enchant dictionary object with the enchant.Dict class with the locale string as its argument.

Then we call d.check with a string to check if the string is an English word.

And we also called d.suggest with a string to check if there’re any English words close to the string argument.

Therefore, we see:

True
['He lo', 'He-lo', 'Hello', 'Helot', 'Help', 'Halo', 'Hell', 'Held', 'Helm', 'Hero', "He'll"]

from the print output.

Conclusion

To check if a word is an English word with Python, we can use the enchant module.