How do I extract all n-element sequences from a list? Example:
a = [0,1,2,3,4]
assert f(a,1) == [[0],[1],[2],[3],[4]]
assert f(a,2) == [[0,1],[1,2],[2,3],[3,4]]
assert f(a,3) == [[0,1,2],[1,2,3],[2,3,4]]
assert f(a,4) == [[0,1,2,3],[1,2,3,4]]
assert f(a,5) == [[0,1,2,3,4]]
What is the fastest implementation of f
?