I'm looking for a an easy way to check whether a certain string is a correctly-spelled English word. For example, 'looked' would return True while 'hurrr' would return False. I don't need spelling suggestions or any spelling-correcting features. Just a simple function that takes a string and returns a boolean value.
-
Hunspell check is very famous, Try its python wrapper. https://datascience.blog.wzb.eu/2016/07/13/autocorrecting-misspelled-words-in-python-using-hunspell/ – Dev_Man Oct 14 '18 at 14:06
4 Answers
Two possible ways of doing it:
- Have your own file which has all the valid words. Load the file into a set and compare each word to see whether it exists in it (word in set)
- (The better way) Use PyEnchant, a spell checking library for Python
PyEnchant is not actively maintained now.

- 1,376
- 18
- 42

- 126,773
- 69
- 172
- 181
-
-
3Use a set rather than a list, and ask `if word in my_set` for better performance. – Karl Knechtel Dec 21 '10 at 15:55
-
@Karl: A very valid point indeed, sets are significantly faster than lists when it comes to determining if an object is present in the set or not. Updated. – user225312 Dec 21 '10 at 16:17
-
-
Instead of list or set, I'll go for [trie tree](https://en.wikipedia.org/wiki/Trie) – venkatvb Jun 30 '15 at 12:03
I was looking for the same functionality and struggled to find an existing library that works in Windows, 64 bit. PyEnchant, although a great library, isn't currently active and doesn't work in 64 bit. Other libraries I found didn't work in Windows.
I finally found a solution that I hope others will find valuable.
The solution...
- Use nltk
- Extract the word list from nltk.corpus.brown
- Convert the word list to a set (for efficient searching)
- Use the
in
keyword to determine if your string is in the set
from nltk.corpus import brown
word_list = brown.words()
word_set = set(word_list)
# Check if word is in set
"looked" in word_set # Returns True
"hurrr" in word_set # Returns False
Use a timer check and you'll see this takes virtually no time to search the set. A test on 1,000 words took 0.004 seconds.

- 3,580
- 1
- 21
- 24
-
1Missing a lot of not terribly uncommon words, e.g. reuse, gleams, cue etc. – Tahlor Mar 29 '18 at 03:27
I personally used: http://textblob.readthedocs.io/en/dev/ It is an active project and according to the website:
Spelling correction is based on Peter Norvig’s “How to Write a Spelling Corrector”[1] as implemented in the pattern library. It is about 70% accurate

- 1,072
- 1
- 9
- 23
-
Textblob is super cool! in installation, usage, documentation. Thanks for sharing – Nov 06 '19 at 16:01