【问题标题】:Textblob word tokenization into arrayTextblob 词标记化为数组
【发布时间】:2015-07-23 02:52:37
【问题描述】:
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 ', 'apple']), WordList(['this', 'is', 'a', 'laptop'])]

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

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

【问题讨论】:

    标签: arrays tokenize textblob


    【解决方案1】:

    您可以在附加到数组2之前列出()它:

    for i in array:
        c=TextBlob(i)
        array2.append(list(c.words))
    

    【讨论】:

      【解决方案2】:
      array2.append(c.words._collection)
      

      【讨论】:

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