
Keywords Finder
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:
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.
Precondition:
0 < len(text) < 5000
0 < len(the_number_of_key_words) < 30
CheckiO Extensions allow you to use local files to solve missions. More info in a blog post.
In order to install CheckiO client you'll need installed Python (version at least 3.8)
Install CheckiO Client first:
pip3 install checkio_client
Configure your tool
checkio --domain=py config --key=
Sync solutions into your local folder
checkio sync
(in beta testing) Launch local server so your browser can use it and sync solution between local file end extension on the fly. (doesn't work for safari)
checkio serv -d
Alternatevly, you can install Chrome extension or FF addon
checkio install-plugin
checkio install-plugin --ff
checkio install-plugin --chromium
Read more here about other functionality that the checkio client provides. Feel free to submit an issue in case of any difficulties.