【发布时间】:2016-06-05 03:07:39
【问题描述】:
我有一个生成 nltk 块的语法标签,
sent_text = nltk.sent_tokenize(text) # this gives us a list of sentences
# now loop over each sentence and tokenize it separately
for sentence in sent_text:
tokenized_text = nltk.word_tokenize(sentence)
tagged = nltk.pos_tag(tokenized_text)
for word, tag in tagged:
print(tag)
这给了我以下输出,
DT
JJ
NN
NN
VBD
IN
DT
JJ
NN
但是,我希望输出像
一样单行 DT JJ NN NN VBD IN DT JJ NN
我该怎么做?
【问题讨论】:
-
python3的
print函数有一个end参数,设置为' ',例如print(tag, end=' '):见docs.python.org/3.5/library/… -
请这样做..添加一个逗号..
print tag, -
@AChampion 在 cmets 中复制我的答案是没有用的
标签: python python-2.7 for-loop nltk