0

I need to clean the misspelling words in a query like "eat an appple", "eat an bannnna". I have tried the autocorrect function but it only works for single words.

from autocorrect import spell
spell("appple")

it returns the correct word "apple". However, for the whole sentence, it does not work.

I wonder if there is any easier way to automatically correct the misspelling words in a sentence without writing a loop.

2
  • 1
    If you want to use the autocorrect package, you'll need to do some kind of iteration over the words in the sentence. Commented Mar 14, 2018 at 19:38
  • What have you tried and what problems have you encountered? Commented Mar 14, 2018 at 19:39

1 Answer 1

3

"Without a loop"

>>> ' '.join(map(spell, 'i like appples'.split()))
'i like apples'

Unfortunately, you still need some mechanism of autocorrecting each word separately, for which a loop, or "looping" construct (such as map) cannot be avoided.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.