来自nltk的函数bigrams返回以下消息,
即使导入了nltk并且其他功能正在运行。有任何想法吗?谢谢。
group_by
答案 0 :(得分:10)
函数bigrams
已返回"生成器"宾语;这是一个Python数据类型,它类似于List,但只在需要时才创建它的元素。如果要将生成器实现为列表,则需要将其显式转换为列表:
>>> list(bigrams(['more', 'is', 'said', 'than', 'done']))
[('more', 'is'), ('is', 'said'), ('said', 'than'), ('than', 'done')]
答案 1 :(得分:0)
<generator object bigrams at 0x0000000002E64240>
当此指令出现时,表示您的双字母组已创建并且已准备好显示。现在,如果您希望它们显示,只需将您的指令放在:
list(bigrams(['more', 'is', 'said', 'than', 'done']))
这意味着您需要以列表形式输出bigrams作为输出,您将获得:
[('more', 'is'), ('is', 'said'), ('said', 'than'), ('than', 'done')]