[Python-ideas] PEP 479: Change StopIteration handling inside generators
Chris Angelico
rosuav at gmail.com
Wed Nov 26 00:31:38 CET 2014
On Wed, Nov 26, 2014 at 8:56 AM, <random832 at fastmail.us> wrote:
> For something more concrete, we can consider a naive implementation of
> iteration over adjacent pairs:
>
> def pairs(x):
> i = iter(x)
> while True:
> yield next(i), next(i)
Okay, it's simple and naive. How about this version:
def pairs(x):
i = iter(x)
for val in i:
yield val, next(i)
Also simple, but subtly different from your version. What's the
difference? Will it be obvious to everyone who reads it?
ChrisA
More information about the Python-ideas
mailing list