Update itertools recipes to use next().
This commit is contained in:
parent
6d327b0d53
commit
21315ba9c8
|
@ -326,14 +326,14 @@ loops that truncate the stream.
|
||||||
return self
|
return self
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
while self.currkey == self.tgtkey:
|
while self.currkey == self.tgtkey:
|
||||||
self.currvalue = next(self.it) # Exit on StopIteration
|
self.currvalue = next(self.it) # Exit on StopIteration
|
||||||
self.currkey = self.keyfunc(self.currvalue)
|
self.currkey = self.keyfunc(self.currvalue)
|
||||||
self.tgtkey = self.currkey
|
self.tgtkey = self.currkey
|
||||||
return (self.currkey, self._grouper(self.tgtkey))
|
return (self.currkey, self._grouper(self.tgtkey))
|
||||||
def _grouper(self, tgtkey):
|
def _grouper(self, tgtkey):
|
||||||
while self.currkey == tgtkey:
|
while self.currkey == tgtkey:
|
||||||
yield self.currvalue
|
yield self.currvalue
|
||||||
self.currvalue = next(self.it) # Exit on StopIteration
|
self.currvalue = next(self.it) # Exit on StopIteration
|
||||||
self.currkey = self.keyfunc(self.currvalue)
|
self.currkey = self.keyfunc(self.currvalue)
|
||||||
|
|
||||||
|
|
||||||
|
@ -652,8 +652,7 @@ which incur interpreter overhead.
|
||||||
def pairwise(iterable):
|
def pairwise(iterable):
|
||||||
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
|
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
|
||||||
a, b = tee(iterable)
|
a, b = tee(iterable)
|
||||||
for elem in b:
|
next(b, None)
|
||||||
break
|
|
||||||
return zip(a, b)
|
return zip(a, b)
|
||||||
|
|
||||||
def grouper(n, iterable, fillvalue=None):
|
def grouper(n, iterable, fillvalue=None):
|
||||||
|
|
Loading…
Reference in New Issue