Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Elegant way solution in Clear category for Monkey Typing by zgub4
import re
def count_words(text, words):
text = text.lower()
counter = 0
for word in words:
exp = r'.*' + word + '.*'
if re.match(exp, text):
counter += 1
return counter
if __name__ == '__main__':
assert count_words("How aresjfhdskfhskd you?", {"how", "are", "you", "hello"}) == 3, "Example"
assert count_words("Bananas, give me bananas!!!", {"banana", "bananas"}) == 2, "BANANAS!"
assert count_words("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
{"sum", "hamlet", "infinity", "anything"}) == 1, "Weird text"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
Oct. 21, 2017