Skip to content
Advertisement

Finding words within paragraph using Python [closed]

Let say I have the following words, Test_wrds = ['she', 'her','women'] that I would like to see whether any one of them present in the following str paragraph,

JavaScript

The question is, How to find these Test_wrds in text and bold them in different colours as well as count them how many times Test_wrds appeared in Para. So I am expecting output something like this,

JavaScript

So far, I have written the following codes:

JavaScript

I am not getting an idea on how to proceed further after this. I used spacy as I found to be powerful and easy for my future coding.
Thanks in advance.

Advertisement

Answer

First of all in order to count how many times each word from Test_wrds list exists in text you can use ORTH which is an ID of the verbatim text content (see here).

JavaScript

Output:

JavaScript

Second, in order to replace each word with bold you can try

JavaScript

Output :

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement