【问题标题】:How to remove "TextBlob" from my output list如何从我的输出列表中删除“TextBlob”
【发布时间】:2021-07-21 21:42:28
【问题描述】:

我最近在尝试 TextBlob,并编写了一个代码来纠正一个拼写错误的句子。

程序将返回更正后的句子并返回拼写错误的单词列表。

这里是代码;

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)

输出是;

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

现在我想从列表中删除TextBlob("...")

有没有办法做到这一点?

【问题讨论】:

  • 您已经使用过map(str,corrected),它也可以帮助您解决问题。

标签: python textblob


【解决方案1】:

您可以将corrected[i] 转换为字符串:

wrng = []

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

输出:['Hello', 'world!', 'I', 'is']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多