I have an array, like:
key = ['*', '(DATE*', '*', '*', '*)', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '(GPE*', '*)', '*', '*', '*', '(DATE)', '*']
I have such an array for which I want to perform task like,
run through the array
once I find the entry starting with '(' but not ending with ')'
replace the next '' entries until we don't find ')' and also replace '*)' with the strip of found entry of starting with '('
and if the entry is within '()' should be just stripped. as for 2nd last element (DATE) to be replaced with DATE only
for E.g. we have 2nd entry '(DATE*' followed by '','','*)' so these entries should be replaced with DATE only
output should be:
key = ['*', 'DATE', 'DATE', 'DATE', 'DATE', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', 'GPE', 'GPE', '*', '*', '*', 'DATE', '*']