I\'m looking for a sliding window splitter of string composed with words with window size N.
Input: \"I love food and I like drink\" , window size 3
You can use iterator with different offsets and zip all of them.
>>> arr = "I love food. blah blah".split()
>>> its = [iter(arr), iter(arr[1:]), iter(arr[2:])] #Construct the pattern for longer windowss
>>> zip(*its)
[('I', 'love', 'food.'), ('love', 'food.', 'blah'), ('food.', 'blah', 'blah')]
You might want to use izip if you have long sentences, or may be plain old loops (like in the other answer).