mirror of https://github.com/mahmoud/boltons.git
BREAKING: finally fixing iterutils.pairwise. pairwise used to call to chunked, now it calls to windowed. pairwise([1, 2, 3, 4]) no longer returns [(1, 2), (3, 4)]. Instead, it returns [(1, 2), (2, 3), (3, 4)], which is what I always mean when I say pairwise.
This commit is contained in:
parent
baf4619c6d
commit
c1c0107fc4
|
@ -234,18 +234,36 @@ def chunked_iter(src, size, **kw):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def pairwise(src, count=None, **kw):
|
def pairwise(src):
|
||||||
"""Convenience function for calling :func:`chunked` with *size* set to
|
"""Convenience function for calling :func:`windowed` on *src*, with
|
||||||
2.
|
*size* set to 2.
|
||||||
|
|
||||||
|
>>> pairwise(range(5))
|
||||||
|
[(0, 1), (1, 2), (2, 3), (3, 4)]
|
||||||
|
>>> pairwise([])
|
||||||
|
[]
|
||||||
|
|
||||||
|
The number of pairs is always one less than the number of elements
|
||||||
|
in the iterable passed in, except on empty inputs, which returns
|
||||||
|
an empty list.
|
||||||
"""
|
"""
|
||||||
return chunked(src, 2, count, **kw)
|
return windowed(src, 2)
|
||||||
|
|
||||||
|
|
||||||
def pairwise_iter(src, **kw):
|
def pairwise_iter(src):
|
||||||
"""Convenience function for calling :func:`chunked_iter` with *size*
|
"""Convenience function for calling :func:`windowed_iter` on *src*,
|
||||||
set to 2.
|
with *size* set to 2.
|
||||||
|
|
||||||
|
>>> list(pairwise_iter(range(5)))
|
||||||
|
[(0, 1), (1, 2), (2, 3), (3, 4)]
|
||||||
|
>>> list(pairwise_iter([]))
|
||||||
|
[]
|
||||||
|
|
||||||
|
The number of pairs is always one less than the number of elements
|
||||||
|
in the iterable passed in, or zero, when *src* is empty.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return chunked_iter(src, 2, **kw)
|
return windowed_iter(src, 2)
|
||||||
|
|
||||||
|
|
||||||
def windowed(src, size):
|
def windowed(src, size):
|
||||||
|
|
Loading…
Reference in New Issue