I have a list of combination of words like "brown fox", and bunch of sentences to check. I just want to find how many times the elements from the list occur in the sentence.
I have a working solution but I want to make it faster. So I just want to have an opinion or any alternative way to do things.
Nothing is case sensitive.
The solution I have works well when my list of keywords is small. What if my list of keywords is 80 elements and my sentence is only two or three words? It will be slow. Is there any way to improve the solution?
harry_line = "The Dark Lord Voldemort is
shooting another shooter who claimed to be Dark Lord."
keywords = ['Dark Lord', 'shooter', 'plan', 'poncho', 'brown fox', 'ugly cake piece']
print(sum(harry_line.count(phrase) for phrase in keywords))
In above example Dark Lord is occuring twice and shooter once thus giving output of 3 which is correct.