Skip to content

Instantly share code, notes, and snippets.

@DayuanJiang
DayuanJiang / Python
Created February 22, 2022 03:02
highlight keywords in jupyter notebook
from termcolor import colored
def _highlight_keyword(text, keyword, color="red"):
if keyword not in text:
return text
colored_text = ""
while text.find(keyword) > -1:
colored_text += text[:text.find(keyword)]
colored_text += colored(keyword, color)
text = text[text.find(keyword) + len(keyword):]
return colored_text + text