pairwise

compas.itertools.pairwise(iterable)[source]

Returns a sliding window of size 2 over the data of the iterable.

Parameters:
iterableiterable

A sequence of items.

Yields:
tuple

Two items per iteration, if there are at least two items in the iterable.

Examples

>>> for a, b in pairwise(range(5)):
...     print(a, b)
0 1
1 2
2 3
3 4