For some reason this code is not working correctly. I am trying to only replace dashes that do not have whitespace around them. However, dashes are still getting replaced when there is no white space.
ls = []
for idx, letter in enumerate(line):
if letter == '-':
ls.append(idx)
for m in ls:
if line[m-1].isspace() == True and line[m+1].isspace() == True:
line = line[m].replace('-', ' @-@ ')
For example:
If thieves came to you, if robbers by night -- oh, what disaster awaits you -- wouldn't they only steal until they had enough? If grape pickers came to you, wouldn't they leave some gleaning grapes?
How Esau will be ransacked! How his hidden treasures are sought out example-case!
Gives:
If thieves came to you , if robbers by night @-@ @-@ oh , what disaster awaits you @-@ @-@ wouldn ' t they only steal until they had enough ? If grape pickers came to you , wouldn ' t they leave some gleaning grapes ?
How Esau will be ransacked ! How his hidden treasures are sought out example @-@ case !
Note: there is other data tokenization going on here.
Desired output is:
If thieves came to you , if robbers by night -- oh , what disaster awaits you -- wouldn ' t they only steal until they had enough ? If grape pickers came to you , wouldn ' t they leave some gleaning grapes ?
How Esau will be ransacked ! How his hidden treasures are sought out example @-@ case !
Thank you for your help!