On Tue, Nov 25, 2014 at 5:26 PM, <random832@fastmail.us> wrote:
def pairs(x):
    i = iter(x)
    while True:
        yield next(i), next(i)

That's not too pythonic, and trying to support non-pythonic code while evolving the language is a dead-end street.

The web documents pythonic ways to obtain pairs from an iterable:

def pairs(x):
    i = iter(x)
    return zip(i, i)

Or even:

def pairs(x):
     return zip(*[iter(x)]*2)

The usual way of dealing with an odd number of elements is to use zip_longest.

I don't remember seeing documented that raising StopIteration will cancel more than one iterator. If it's undocumented, then code that relies on the non-feature is broken.

Cheers,

--
Juancarlo Añez