Sophie has found a stash books and she wants to find information about the ancients who lived on the islands. Unfortunately, she does not have a text search module and needs some help. Let's write a program to help her search for keywords on the pages of a book.
You are given some plain text (without tags) and a string with keywords (or parts of words, or letters) separated by spaces. You will need to find all the keywords and put these words into " <span></span> " wrappers to highlight them for Sophie. You can ignore upper or lower cases for the key words, but the original letter cases in the text should remain.
For the cases when keywords contain or intersect each other you should highlight the larger word without nested span tags.
Let's look it with example.
The text "Hello... and keywords .
The word contains two keywords thus we tag only larger part .
contains two intersected words and and we tag the larger part again .
Be careful, a result like is considered wrong because it contains nested tags.
Two arguments. A text and key words as strings.
The text with wrapped key words.
assert ( checkio("This is only a text example for task example.", "example") == "This is only a text <span>example</span> for task <span>example</span>." ) assert ( checkio("Python is a widely used high-level programming language.", "pyThoN") == "<span>Python</span> is a widely used high-level programming language." ) assert ( checkio("It is experiment for control groups with similar distributions.", "is im") == "It <span>is</span> exper<span>im</span>ent for control groups with s<span>im</span>ilar d<span>is</span>tributions." ) assert ( checkio("The National Aeronautics and Space Administration (NASA).", "nasa THE") == "<span>The</span> National Aeronautics and Space Administration (<span>NASA</span>)." )
How it is used: You see this task every day when use your browser or work with documents. Every time when you search something on the page and want to see the found fragments as highlighted parts, you encounter the concept seen in this task. This problem can be more complex if you use it for the languages where you need to write "lowercase" rules.
0 < len(text) < 5000
0 < len(the_number_of_key_words) < 30