0

I'm trying TextBlob lately and wrote a code to correct a sentence with misspelt words.

The program will return the corrected sentence and also return the list of misspelt words.

Here is the code;

from textblob import TextBlob as tb

x=[]
corrected= []
wrng = []
inp='Helllo wrld! Mi name isz Tom'
word = inp.split(' ')

for i in word:
    x.append(tb(i))

for i in x:
    w=i.correct()
    corrected.append(w)
sentence = (' '.join(map(str,corrected)))
print(sentence)

for i in range(0,len(x)):
    if(x[i]!=corrected[i]):
        wrng.append(corrected[i])
print(wrng)

The Output is;

Hello world! I name is Tom
[TextBlob("Hello"), TextBlob("world!"), TextBlob("I"), TextBlob("is")]

Now I want to remove the TextBlob("...") from the list.

Is there any possible way to do that?

1
  • You have already used map(str,corrected) which can help with your problem, too. Commented Jul 21, 2021 at 21:49

1 Answer 1

0

You can convert corrected[i] to string:

wrng = []

for i in range(0,len(x)):
    if(x[i]!=corrected[i]):
        wrng.append(str(corrected[i]))
print(wrng)

Output: ['Hello', 'world!', 'I', 'is']

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.