Jan-25-2019, 03:51 PM
from colorama import Fore, Back, Style, init
import fpdf
from fpdf import FPDF
init()
paragraph = 'Whatever blame emerges! Its gasoline avoids the prison. The unlimited mania varies an exotic garage. A curtain farms? The sunrise fells an assorted companion around the jet.'
key_words = ['blame', 'avoids', 'unlimited', 'exotic']
def highlight(word):
if word in key_words:
return Fore.RED + str(word) + Fore.RESET
else:
return str(word)
textpara = paragraph.strip().split(' ')
colored_words = list(map(highlight, textpara))
final = " ".join(colored_words)
print (final)I have created a code which highlight the keywords in a paragraph. I ran it in the cmd and it works fine (output is in the attachment). How do I save this output into file or PDF with colours highlighted so I don't have to re run the code again?I tried to copy and paste the output into a text file but the colours did not show up
Thanks for the help
