The tuples inside the file:
(\'Wanna\', \'O\')
(\'be\', \'O\')
(\'like\', \'O\')
(\'Alexander\', \'B\')
(\'Coughan\', \'I\')
(\'?\', \'O\')
I'll extend the input data to include more 'B' + 'I'
examples.
phrases = [('Wanna', 'O'),
('be', 'O'),
('like', 'O'),
('Alexander', 'B'),
('Coughan', 'I'),
('One', 'B'),
('Two', 'I'),
('Three', 'B')]
length = len(phrases)
res = ['%s %s' % (phrases[i][0], phrases[i + 1][0])
for i in range(length)
if i < length - 1 and phrases[i][1] == 'B' and phrases[i + 1][1] == 'I']
print(res)
The result is:
['Alexander Coughan', 'One Two']