I'm having somewhat of a difficult problem obtaining items in tuples. I have a list of tuples and it looks like this (containing a word and a tag):
[('An', 'DET'),
('autumn', 'NOUN'),
('evening', 'NOUN'),
('.', '.'),
('In', 'ADP'),
('an', 'DET'),
('old', 'ADJ'),
('woodshed', 'NOUN'),
('The', 'DET'),
('long', 'ADJ'),
('points', 'NOUN'),
('of', 'ADP'),
('icicles', 'NOUN'),
('Are', 'NOUN'),
('sharpening', 'VERB'),
('the', 'DET'),
('wind', 'NOUN'),
('.', '.')....]
What I would like to do is iterate through these tuples and determine the likelihood of what the next word tag is based on the previous one. For instance, if I wanted to determine how many times 'DET' appears in front of a 'NOUN', I would want to iterate through the tuples and determine, for instance:
number of times 'DET' appears in front of 'NOUN'
So far, I have tried this:
prob = 0.0
for item in tuples:
if item[1] == "DET" and item + 1[1] == "NOUN"
return prob
The if
statement is obviously not correct. Does anyone know what I can do to access the next item?