1
from textblob import TextBlob
import nltk
array=("i have a bunch of grapes","i like to eat apple","this is a laptop")
array2=[]



for i in array:

    c=TextBlob(i)
    array2.append(c.words)

print array2

打印出来的结果是:

[WordList(['i', 'have', 'a', 'bunch', 'of', 'grapes']), WordList(['i', 'like', 'to', 'eat', '苹果']), WordList(['this', 'is', 'a', 'laptop'])]

我如何从 WordList 中提取,以便我的 array2 将打印为:

[['i', 'have', 'a', 'bunch', 'of', 'grapes'],['i', 'like', 'to', 'eat', 'apple'],[ “这是一台笔记本电脑”]]

4

2 回答 2

1

您可以在附加到 array2 之前列出()它:

for i in array:
    c=TextBlob(i)
    array2.append(list(c.words))
于 2020-01-16T19:28:48.297 回答
0
array2.append(c.words._collection)
于 2017-12-06T14:44:46.730 回答