-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount_words.pu.py
More file actions
24 lines (22 loc) · 897 Bytes
/
count_words.pu.py
File metadata and controls
24 lines (22 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def count_words(text: str, words: set) -> int:
t=text.lower()
s=t.split()
sum={}
for i in words:
for j in s:
if i in j:
if i not in sum:
sum[i]=1
else:
sum[i]+=1
count=0
for i in sum:
count+=1
return count
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
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!")