Function nonoverlap
from raimad.iters
def nonoverlap(n: int, seq: collections.abc.Sequence[~T]) -> collections.abc.Iterable[collections.abc.Iterable[~T]]
Iterate n items at a time, without overlap.
Truncates the iterable such that it is a multiple of n.
overlap(2, [1,2,3,4,5,6]) = [
[1,2],
[3,4],
[5,6],
]
overlap(2, [1,2,3,4,5]) = [
[1,2],
[3,4],
]
Click to show code
def nonoverlap(n: int, seq: Sequence[T]) -> Iterable[Iterable[T]]:
"""
Iterate n items at a time, without overlap.
Truncates the iterable such that it is a multiple of n.
overlap(2, [1,2,3,4,5,6]) = [
[1,2],
[3,4],
[5,6],
]
overlap(2, [1,2,3,4,5]) = [
[1,2],
[3,4],
]
"""
return zip(*[seq[offset::n] for offset in range(n)])