0

So I want to identify and count misspelled words.

I have managed to identify them, but it seems I cannot count them... Please bear in mind I am new to Python. I tried len, but it returned me the length of the word, and I tried count but I got nothing.

From the code below, I want to count the variable "wrong_words".

What am I doing wrong?

P.S:to be crystal clear, the misspelled words are 'hapenning', 'protugal'. And I want as output the sum of them, hence 2.

Thank you

from spellchecker import SpellChecker

spell = SpellChecker()

# find those words that may be misspelled
misspelled = spell.unknown(['something', 'is', 'hapenning', 'here', 'protugal'])

for word in misspelled:
    # Get the one `most likely` answer
    wrong_words = spell.correction(word)
    print(wrong_words)

Mig
  • 139
  • 2
  • 10
  • Hi @Mig can you tell what does `spell.correction(word)` returns if the word is spelled correctly? –  May 04 '20 at 21:17
  • Hi @overflow95, it doesn't return anything. The spell.correction(word) only gets the misspelled words. – Mig May 04 '20 at 21:22
  • What you are expecting is number of misspelled words in `misspelled`? In the list given above it should be 2,right? –  May 04 '20 at 21:24
  • Yes exactly. Just to be crystal clear, the words that are misspelled are 'hapenning' and 'protugal'. I will clarify the original post, thanks – Mig May 04 '20 at 21:25
  • 3
    You can create a count variable and then check if word is misspelled and then increase this count. `count=0` `for word in misspelled`: `if spell.correction(word):` `count+=1` count will give you number of misspelled words. –  May 04 '20 at 21:28
  • That is exactly what I am looking for. Much appreciated. – Mig May 04 '20 at 21:32

0 Answers0