I'm opening file and searching for specific word to replace the last 2 occurrence of that word in a file.
I have opened file and try to replace but it is replacing first 2 occurrence. where as i want to replace last two occurence
s = open("mount.txt").read()
s = s.replace('mickey', 'minnie',2)
f = open("mount.txt", 'w')
f.write(s)
f.close()
This is text is just for example. Actual text is different.
#mount.txt#
I'm mickey. minnie is my friend.
mickey is the good name given by my parents.
mickey loves to play cricket.
Where as his parents doesn't like Mickey's habit.
#Replaces text[mount.txt]#
I'm mickey. minnie is my friend.
Mickey is the good name given by my parents.
minnie loves to play cricket.
Where as his parents doesn't like minnie's habit.