Jan-25-2019, 03:51 PM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
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 tried to copy and paste the output into a text file but the colours did not show up
Thanks for the help