I have a trigram like
trigrm = [((w1,tag1), (w2,tag2),(w3,tag3))]
I would like to extract only tags of each word from above trigram in a tuple like
tup = (tag1,tag2,tag3)
I have a trigram like
trigrm = [((w1,tag1), (w2,tag2),(w3,tag3))]
I would like to extract only tags of each word from above trigram in a tuple like
tup = (tag1,tag2,tag3)
You can try:
>>> 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')
You can use zip. Here is an example using strings because I don't know the variable values
trigrm = [(('w1','tag1'), ('w2','tag2'),('w3','tag3'))]
tuples = list(zip(*trigrm[0]))[1]
print (tuples)
# ('tag1', 'tag2', 'tag3')