[issue5350] Modification to pairwise in itertools recipes
New submission from Matteo Dell'Amico de...@linux.it: 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). -- assignee: georg.brandl components: Documentation messages: 82626 nosy: della, georg.brandl severity: normal status: open title: Modification to pairwise in itertools recipes ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5350 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5350] Modification to pairwise in itertools recipes
Georg Brandl ge...@python.org added the comment: Assigning to Raymond. Note that for elem in b: break and next(b) are not equivalent when b is empty/exhausted. -- assignee: georg.brandl - rhettinger nosy: +rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5350 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5350] Modification to pairwise in itertools recipes
Matteo Dell'Amico de...@linux.it added the comment: 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) for x, y in zip(a, b): yield x, y ...which is not that attractive anymore, also because it's slower. Sorry for the error. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5350 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5350] Modification to pairwise in itertools recipes
Changes by David W. Lambert lamber...@corning.com: -- nosy: +LambertDW ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5350 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5350] Modification to pairwise in itertools recipes
Raymond Hettinger rhettin...@users.sourceforge.net added the comment: Applied in r69908 . -- resolution: - accepted status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5350 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5350] Modification to pairwise in itertools recipes
David W. Lambert lamber...@corning.com added the comment: Nice. I had thought of this a while ago but found counter example, probably using the empty iterator def f(): raise StopIteration yield I didn't realize next had optional argument. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5350 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5350] Modification to pairwise in itertools recipes
Georg Brandl ge...@python.org added the comment: Shame on me, I forgot about the optional argument too. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5350 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5350] Modification to pairwise in itertools recipes
Matteo Dell'Amico de...@linux.it added the comment: great Raymond! :) ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5350 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com