• + 1 comment

    With python 3 you can make use of the collections.Counter.

    Like other comments already stated, make sure to read the input using sys.stdin.read() and lowercase the text. Everything else is very straight forward.

    A possible solution could look like this:

    from collections import Counter
    from functools import reduce
    from operator import iconcat
    
    def getSentences(text):
        return text.lower().split('.')
    
    def getTrigrams(sentence):
        words = sentence.split()
        return [" ".join(words[i:i+3]) for i in range(len(words)-2)]
    
    if __name__ == '__main__':
        text = sys.stdin.read()
        trigrams = Counter(reduce(iconcat, map(getTrigrams, getSentences(text)), []))
        print(max(trigrams, key=trigrams.get))