pythontextblob

How to remove "TextBlob" from my output list


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?


Solution

  • 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']