Thread Modes python-docx- change lowercase to bold, italic

In my docx file there are pieces of text i have to process such as making words italic, bold or underlined.

Example

input: In the future, if you try hard you will fail a lot

I used this code:

from docx import Document
import re

def change(filename,key):
    doc = Document(filename)
    for p in doc.paragraphs:
        text = p.text
        split_text = text.split(key)
        for i in split_text[:-1]:
            p.add_run(i)
            font = p.add_run(key).bold = True
        p.add_run(split_text[-1])
    doc.save('test.docx')
path = r'path of file'
change(path,'key')

but the result is

In the future, if you try hard you will fail a lotIn the future

What do I have to do so that the output is

output: In the future, if you try hard you will fail a lot

you should only select and replace “future”.