Import next () python 2.5

I am using a slightly modified version of the paired recipe from itertools, which looks like

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 that 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 change a function to make it work?

+6
source share
1 answer

You can easily determine the 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 
+10
source

Source: https://habr.com/ru/post/921315/


All Articles