You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Modification to "pairwise" in itertools recipes #49600
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/rhettinger'closed_at=<Date2009-02-23.19:40:08.891>created_at=<Date2009-02-23.13:37:11.058>labels= ['docs']
title='Modification to "pairwise" in itertools recipes'updated_at=<Date2009-02-23.21:57:27.667>user='https://bugs.python.org/della'
I feel that the "pairwise" recipe could be slightly more elegant if "for
elem in b: break" became a simpler next(b) (or b.next() for Python 2.x).
It is also more natural to modify the recipes to suit one's needs (e.g.,
returning items with a given gap between them, or convert the recipe to
k-wise iteration).
Georg, you're right, there's a StopIteration to catch. My thinko was
mistaking the function for a generator where the exception propagation
would have done the right thing. The amended version now becomes
next(b)
forx, yinzip(a, b): yieldx, y
...which is not that attractive anymore, also because it's slower. Sorry
for the error.
Activity
della commentedon Feb 23, 2009
I feel that the "pairwise" recipe could be slightly more elegant if "for
elem in b: break" became a simpler next(b) (or b.next() for Python 2.x).
It is also more natural to modify the recipes to suit one's needs (e.g.,
returning items with a given gap between them, or convert the recipe to
k-wise iteration).
birkenfeld commentedon Feb 23, 2009
Assigning to Raymond.
Note that "for elem in b: break" and "next(b)" are not equivalent when b
is empty/exhausted.
della commentedon Feb 23, 2009
Georg, you're right, there's a StopIteration to catch. My thinko was
mistaking the function for a generator where the exception propagation
would have done the right thing. The amended version now becomes
...which is not that attractive anymore, also because it's slower. Sorry
for the error.
rhettinger commentedon Feb 23, 2009
Applied in r69908 .
lambertdw commentedon Feb 23, 2009
Nice. I had thought of this a while ago but found counter example,
probably using the empty iterator
I didn't realize "next" had optional argument.
birkenfeld commentedon Feb 23, 2009
Shame on me, I forgot about the optional argument too.
della commentedon Feb 23, 2009
great Raymond! :)