I'm using a slightly altered version of the pairwise recipe from itertools which looks like this
def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b) 
Now it turns out I need to run the code with python 2.5 where the next() function throws the following exception:
<type 'exceptions.NameError'>: global name 'next' is not defined
Is there a way to use next() with python 2.5? Or how do I need to modify the function to make it work anyhow?
You can easily provide a definition of this function yourself:
_sentinel = object()
def next(it, default=_sentinel):
    try:
        return it.next()
    except StopIteration:
        if default is _sentinel:
            raise
        return default
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With