Skip to content

Commit 08c2f86

Browse files
committed
By Zhao Kun Peng
1 parent a31cb71 commit 08c2f86

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

checkio/count_words.pu.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def count_words(text: str, words: set) -> int:
2+
t=text.lower()
3+
s=t.split()
4+
sum={}
5+
for i in words:
6+
for j in s:
7+
if i in j:
8+
if i not in sum:
9+
sum[i]=1
10+
else:
11+
sum[i]+=1
12+
count=0
13+
for i in sum:
14+
count+=1
15+
return count
16+
17+
18+
if __name__ == '__main__':
19+
#These "asserts" using only for self-checking and not necessary for auto-testing
20+
assert count_words("How aresjfhdskfhskd you?", {"how", "are", "you", "hello"}) == 3, "Example"
21+
assert count_words("Bananas, give me bananas!!!", {"banana", "bananas"}) == 2, "BANANAS!"
22+
assert count_words("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
23+
{"sum", "hamlet", "infinity", "anything"}) == 1, "Weird text"
24+
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")

0 commit comments

Comments
 (0)