I'm writing a function to implement the solution to finding the number of times a word occurs in a list of elements, retrieved from a text file which is pretty straightforward to achieve.
However, I have been at it for two days trying to figure out how to check occurrences of a string which contains multiple words, can be two or more
So for example say the string is:
"hello bye"
and the list is:
["car", "hello","bye" ,"hello"]
The function should return the value 1
because the elements "hello" and "bye" only occur once consecutively.
The closest I've gotten to the solution is using
words[0:2] = [' '.join(words[0:2])]
which would join two elements together given the index. This however is wrong as the input given will be the element itself rather than an index.
Can someone point me to the right direction?