The problem you are explaining can be easily solved using regular expressions in python. In python you can use the re module to perform tasks relating to regular expressions.
For the problem that you have outlined, you can use the sub method from the re module in python. The sub method substitutes anything that matches a given pattern with a given string, like this:
re.sub(r'.*I', 'I', string)
If you wish to get a deeper understanding of python you can take a look at this, youtube video: