I'm using a name entity recognition model to find names in a text string. For hyphenated names like Jane Miller-Smith, the NER model returns the names seperately like this:
names = ['Jane','Miller','-','Smith']
What's a simple way to join the items before and after the '-' to one string in this list? So that I have a list of first and last name like name = ['Jane', 'Miller-Smith']?
I've so far tried to loop through the list of names based on solutions like this for different hyphenated name versions:
name1 = ['Jane', 'Miller', '-','Smith']
name = ['Jane', '-', 'Marie','Miller', '-','Smith']
new_name = []
for cur, nxt in zip (name, name [1:]):
print(cur,nxt)
if cur == '-':
hyph = cur+nxt
new_name.append(hyph)
print("hyph: ", hyph)
else:
new_name.append(cur)
print("cur: ", cur)
print(new_name)
But I can't wrap my head around how to combine only the string before and after the hypen and also keep other non-hyphenated strings in the list in order (so that not the last name is suddenly first).