window¶
- emlib.iterlib.window(iterable, size=3, step=1)[source]¶
iterate over subseqs of iterable
- Parameters:
iterable (
Iterable
[TypeVar
(T
)]) – an iterablesize – the size of the window
step – the step size
- Return type:
Iterator
[tuple
[TypeVar
(T
),...
]]- Returns:
an iterator over a tuple of items of iterable, windowed as indicated
Example
>>> seq = range(6) >>> list(window(seq, 3, 1)) [(0, 1, 2), (1, 2, 3), (2, 3, 4), (3, 4, 5)] >>> list(window(seq, 3, 2)) [(0, 1, 2), (2, 3, 4)] # the same as pairwise >>> list(window(range(5), 2, 1)) [(0, 1), (1, 2), (2, 3), (3, 4)]