Keywords Finder Keywords Finder
Moderate
English

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 World! Or LOL" and keywords "hell world or lo".
The word "World" contains two keywords thus we tag only larger part "<span>World</span>".
"Hello" contains two intersected words "hell" and "lo" and we tag the larger part again "<span>Hello</span>".
Be careful, a result like "<span>Hel<span>lo</span></span>" is considered wrong because it contains nested tags.

Input: Two arguments. A text and key words as strings.

Output: The text with wrapped key words.

Example:

checkio("This is only a text example for task example.", "example") ==
        "This is only a text example for task example."

checkio("Python is a widely used high-level programming language.", "pyThoN") ==
        "Python is a widely used high-level programming language.")

checkio("It is experiment for control groups with similar distributions.", "is im") ==
        "It is experiment for control groups with similar distributions.")

checkio("The National Aeronautics and Space Administration (NASA).", "nasa  THE") ==
        "The National Aeronautics and Space Administration (NASA).")

checkio("Did you find anything?", "word space tree") ==
        "Did you find anything?")
checkio("Hello World! Or LOL", "hell world or lo") ==
        "Hello World! Or LOL"
    

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.

Precondition:
0 < len(text) < 5000
0 < len(the_number_of_key_words) < 30