我有一个以token/tag格式标记的文件,我尝试使用一个函数,返回一个(word,tag)列表中的单词元组。
在Python 2.7中它工作良好,但在Python 3.4中,在最后一行显示错误,提示“TypeError: 'zip' object is not subscriptable”。为什么它停止工作了?我该如何修复它?
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中,在最后一行显示错误,提示“TypeError: 'zip' object is not subscriptable”。为什么它停止工作了?我该如何修复它?
在Python 2到Python 3的过程中,还有其他几件事情以类似的方式发生了变化;请参见如何在Python 3中使用filter、map和reduce。