window
- compas.itertools.window(seq, n=2)[source]
Returns a sliding window (of width n) over the data from the iterable.
- Parameters:
- seqiterable
A sequence of items.
- nint, optional
The width of the sliding window.
- Yields:
- tuple
A tuple of size n at every iteration, if there are at least n items in the sequence.
Examples
>>> for view in window(range(10), 3): ... print(view) (0, 1, 2) (1, 2, 3) (2, 3, 4) (3, 4, 5) (4, 5, 6) (5, 6, 7) (6, 7, 8) (7, 8, 9)