Suppose we have the following list:
['O', 'O', 'O', 'O', 'I-INS', 'I-INS', 'I-INS', B-PER, I-PER]
I want to change this list, so that anytime there are multiple members of a subgroup (like INS) starting with I- without a B- member behind them, the first element changes to B-, for example:
O,I-INS,I-INS,I-INS,B-PER, I-PER => O,B-INS,I-INS,I-INS,B-PER, I-PER
If a subgroup already starts with a B- or anything else other than I, then it should remain unchanged. So far, I have written this code:
temp = []
for i in range(len(iobTags)):
if iobTags[i].startswith('I'):
if iobTags[i-1].startswith('I'):
temp = iobTags[i-1].split('-')
temp[0] = 'B'
mem = temp[0] + '-' + temp[1]
iobTags[i-1] = mem
else:
continue
The problem is that this code keeps changing every I- member that it sees to B- after the first element like:
I-INS,I-INS,I-INS => B-INS,B-INS,I-INS
While I just want the first element to change and then move on to checking the first element of other subgroups. How can I change this code?