window_fixed_size¶
- emlib.iterlib.window_fixed_size(seq, size, maxstep)[source]¶
A sliding window over subseqs of seq
Each returned subseq has the given size and the step between each subseq is at most ‘maxstep’. If the last window does not fit evenly, a smaller step is taken. If seq has less elements than size, a ValueError is raised :rtype:
Iterable
[tuple
[TypeVar
(T
),...
]]Note
The difference with window is that window drops the last elements if they don’t fit evenly in the window size
Example
>>> list(window_fixed_size(range(10)), 5,2) [[0, 1, 2, 3, 4], [2, 3, 4, 5, 6], [4, 5, 6, 7, 8], [5, 6, 7, 8, 9]] # Notice that the step of the last window is 1 and not 2
>>> list(window(range(10), 5, 2)) [(0, 1, 2, 3, 4), (2, 3, 4, 5, 6), (4, 5, 6, 7, 8)] # element 9 is missing