I need a rolling window (aka sliding window) iterable over a sequence/iterator/generator. Default Python iteration can be considered a special case, where the window length
I tested a few solutions and one I came up with and found the one I came up with to be the fastest so I thought I would share it.
import itertools import sys def windowed(l, stride): return zip(*[itertools.islice(l, i, sys.maxsize) for i in range(stride)])