Add utils.pairwise().
This commit is contained in:
parent
26ba867089
commit
3407bac38b
1 changed files with 8 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue