'How to split text in python count number of occurrences in a list of strings
def find_occurrences(text, itemsList):
count = dict()
words = text.split()
return count;
assert find_occurrences(['welcome to our Python program', 'Python is my favourite language!', 'I love Python'], 'Python')
assert find_occurrences(['this is the best day', 'my best friend is my dog'], 'best')
I have to write code that will help me count the number of occurrences of a word inside a list of sentences.
I am trying to split the text, but it will not allow me to. I think I need to find a way to read the sentence and then split it, but I am unable to think of a way to do so. If anyone can help or point me in the right direction that would be helpful.
I probably could figure out the rest from there.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
