【发布时间】:2014-12-11 20:01:23
【问题描述】:
我有一个格式为 token/tag 的标记文件,我尝试了一个函数,该函数返回一个包含 (word,tag) 列表中单词的元组。
def text_from_tagged_ngram(ngram):
if type(ngram) == tuple:
return ngram[0]
return " ".join(zip(*ngram)[0]) # zip(*ngram)[0] returns a tuple with words from a (word,tag) list
在 python 2.7 中它运行良好,但在 python 3.4 中它给了我以下错误:
return " ".join(list[zip(*ngram)[0]])
TypeError: 'zip' object is not subscriptable
有人可以帮忙吗?
【问题讨论】:
-
nelsonslog.wordpress.com/2015/04/20/python3-zip-is-a-hassle 有一个您可能感兴趣的解决方法。
标签: python python-3.x