From 3407bac38b85e8424e1bfdd92e6dd5e3f4aa3b38 Mon Sep 17 00:00:00 2001 From: Andrey Golovizin Date: Fri, 15 Aug 2014 14:20:34 +0200 Subject: [PATCH] Add utils.pairwise(). --- pixelocr/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pixelocr/utils.py b/pixelocr/utils.py index c1fc320..df3d9a4 100644 --- a/pixelocr/utils.py +++ b/pixelocr/utils.py @@ -15,6 +15,8 @@ import functools +import itertools + def cached_property(fun): """A memoize decorator for class properties.""" @@ -36,3 +38,9 @@ def collect_iterable(func): def collect(*args, **kwargs): return list(func(*args, **kwargs)) return collect + + +def pairwise(iterable): + a, b = itertools.tee(iterable) + next(b, None) + return itertools.zip_longest(a, b)