I got the correct output. I will look into the answers given above. My code is given below.
import codecs
fq = codecs.open('resolvedanaphora.txt', encoding='utf-8')
lines = fq.readlines()
fq.close()
fa = codecs.open('resolvedana.txt', 'w')
for i in lines:
words=i.split()
for i in range(2,len(words)):
if words[i]=='-->':
words[i]=''
words[i-1]= ''
for w in words:
if w!='':
fa.write(w.encode('UTF-8'))
fa.write(' ')
fa.write('\n')
fa.close()
If a item in list is '-->' then the current item and previous item is replaced by ''. Since '' is not needed to be written in the output file, it is ignored.
The output is :
അദ്ദേഹം --> മന്മോഹന്സിംഗ്
അദ്ദേഹത്തെ --> മന്മോഹന്സിംഗ്
അവന് --> രാമന്
അവള്ക്ക് --> സീതയെ
അവള് --> സീതയെ
അത് --> പൂവ്
അവര് --> സീതയെ , രാമന്
അവിടെ --> കോട്ടയത്ത്
അവര്ക്ക് --> സീതയെ , രാമന്
അവിടെ --> കോട്ടയത്ത്
അവന് --> ലക്ഷ്മനനെ
അവനെ --> ലക്ഷ്മണന്
അവള്ക്ക് --> സീതയെ
അവന് --> രാമന്