我有个三联图
trigrm = [((w1,tag1), (w2,tag2),(w3,tag3))]
我只想从上面的三元组中提取每个单词的标签
tup = (tag1,tag2,tag3)
最佳答案
您可以尝试:
>>> trigrm = [(("w1","tag1"), ("w2","tag2"),("w3","tag3"))]
>>> output = ([x[1] for x in trigrm[0]])
>>> print output
['tag1', 'tag2', 'tag3']
>>> tuple(output)
('tag1', 'tag2', 'tag3')
关于python - Python Trigram转换为元组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54217122/