Occurrences After Bigram
We can solve this problem by splitting the text into words, and then traversing the list of words. For each position, we check if the word at this position and the two preceding words match the pattern “first second third”. If they do, we add the third word to the result.
Python solution:
|
|
In this code, we start by splitting the input text into words. Then we initialize an empty list to store the result. We traverse the list of words, starting from the third word (since we need two preceding words to match the pattern “first second third”). For each position, we check if the word at this position and the two preceding words match the pattern “first second third”. If they do, we append the third word to the result. After traversing all the words, we return the result.