loop_in_pairs¶
- pyhelpers.ops.loop_in_pairs(iterable)[source]¶
Generate pairs of consecutive elements from the given iterable.
- Parameters:
iterable (Iterable) – Iterable object from which to generate pairs.
- Returns:
Zip object containing pairs of consecutive elements.
- Return type:
zip
Examples:
>>> from pyhelpers.ops import loop_in_pairs >>> res = loop_in_pairs(iterable=[1]) >>> list(res) [] >>> res = loop_in_pairs(iterable=range(0, 10)) >>> list(res) [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9)]