Function overlap
from raimad.iters
def overlap(n: int, seq: collections.abc.Sequence[~T]) -> collections.abc.Iterable[collections.abc.Iterable[~T]]
Iterate n items at a time, with overlap. overlap(3, [1,2,3,4,5]) = [ [1,2,3], [2,3,4], [3,4,5], ]
Click to show code
def overlap(n: int, seq: Sequence[T]) -> Iterable[Iterable[T]]: """ Iterate n items at a time, with overlap. overlap(3, [1,2,3,4,5]) = [ [1,2,3], [2,3,4], [3,4,5], ] """ return zip(*[seq[offset:] for offset in range(n)])