12 lines
264 B
Python
12 lines
264 B
Python
import itertools
|
|
from typing import TypeVar, Iterator, Tuple
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
def pairwise(iterable: Iterator[T]) -> Iterator[Tuple[T, T]]:
|
|
"""s -> (s0,s1), (s1,s2), (s2, s3), ..."""
|
|
a, b = itertools.tee(iterable)
|
|
next(b, None)
|
|
return zip(a, b)
|