n = 3 with open('/path/to/file') as my_file: words = my_file.read().split() ngrams = zip(*[words[i:] for i in range(n)])