keyword_list = ['cat', 'dog']
string = 'I have a dog and a cat'
Say I have defined keyword_list and string, how can i print the string with keywords bold:
'I have a dog and a cat'
keyword_list = ['cat', 'dog']
string = 'I have a dog and a cat'
Say I have defined keyword_list and string, how can i print the string with keywords bold:
'I have a dog and a cat'
Use replace to add bold to the front of the target text and then end the escape with the end chars on the other side of each target text:
BOLD = '\033[1m'
END = '\033[0m'
keyword_list = ['cat', 'dog']
string = 'I have a dog and a cat'
for i in keyword_list:
string = string.replace(i, BOLD + i + END)
print(string)
More info here