我有一个类似三字母组的
trigrm = [((w1,tag1), (w2,tag2),(w3,tag3))]
我只想从像元组这样的三元组中提取每个单词的标签
tup = (tag1,tag2,tag3)
答案 0 :(得分:2)
ll = [x for _,x in sum(ll,())]
答案 1 :(得分:1)
您可以尝试:
>>> 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')
答案 2 :(得分:1)
您可以使用zip
。这是一个使用字符串的示例,因为我不知道变量值
trigrm = [(('w1','tag1'), ('w2','tag2'),('w3','tag3'))]
tuples = list(zip(*trigrm[0]))[1]
print (tuples)
# ('tag1', 'tag2', 'tag3')