Create a function that, Given Two arguments: A text as a string and words as a set of strings, returns the number of words from the set, that are contained in the string.
Eg. count_words("How aresjfhdskfhskd you?", {"how", "are", "you", "hello"}) == 3
My Attempt:
import re
def count_words(text, words):
count = 0
for i in words:
x = re.compile('.*'+i+'.*')
if x.search(text):
count +=1
return count
I assume this has been answered several times before, but i just could not find a relevant answer, so my apologies. Any help would be appreciated, thanks
howandHoware different strings, should the return value in your example be2instead of3?