Reputation: 1
I want to find a word ('pair) in a list of sentences and add the frequency of each word to a count. I am getting an assertion error but I don't understand where i'm going wrong. Is there a missing step?
def finding_instances(sentences, pair):
counter = 0
for sentence in sentences:
words = sentence.split()
for words in sentences:
if pair in words:
counter += 1
return counter
assert finding_instances(["welcome to the great parade", "good morning", "I enjoy Python", "Welcome in"], "Python") == 1
assert finding_instances(["I hate", "other languages", "I am", "Hello"], "Welcome") == 0
Upvotes: 0
Views: 37
Reputation: 312
You have almost completed!
def finding_instances(sentences, pair):
counter = 0
for sentence in sentences:
words = sentence.split()
if pair in words:
counter += 1
return counter
Upvotes: 1