Skip to content

Commit 3bcc821

Browse files
authored
Create for each dict
1 parent 29a88d3 commit 3bcc821

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

for each dict

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
3+
def count_words(text, words):
4+
5+
result = 0
6+
7+
for each in words:
8+
9+
if each in text.lower():
10+
11+
result += 1
12+
13+
return result
14+
15+
16+
17+
18+
19+
if __name__ == '__main__':
20+
21+
#These "asserts" using only for self-checking and not necessary for auto-testing
22+
23+
assert count_words("How aresjfhdskfhskd you?", {"how", "are", "you", "hello"}) == 3, "Example"
24+
25+
assert count_words("Bananas, give me bananas!!!", {"banana", "bananas"}) == 2, "BANANAS!"
26+
27+
assert count_words("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
28+
29+
{"sum", "hamlet", "infinity", "anything"}) == 1, "Weird text"
30+

0 commit comments

Comments
 (0)