Update itertools recipes to use next().

This commit is contained in:
Raymond Hettinger 2009-02-23 19:32:55 +00:00
parent 52bc7b85fd
commit d47442e3cb
1 changed files with 6 additions and 7 deletions

View File

@ -321,14 +321,14 @@ loops that truncate the stream.
return self
def next(self):
while self.currkey == self.tgtkey:
self.currvalue = self.it.next() # Exit on StopIteration
self.currvalue = next(self.it) # Exit on StopIteration
self.currkey = self.keyfunc(self.currvalue)
self.tgtkey = self.currkey
return (self.currkey, self._grouper(self.tgtkey))
def _grouper(self, tgtkey):
while self.currkey == tgtkey:
yield self.currvalue
self.currvalue = self.it.next() # Exit on StopIteration
self.currvalue = next(self.it) # Exit on StopIteration
self.currkey = self.keyfunc(self.currvalue)
.. versionadded:: 2.4
@ -378,7 +378,7 @@ loops that truncate the stream.
# imap(pow, (2,3,10), (5,2,3)) --> 32 9 1000
iterables = map(iter, iterables)
while True:
args = [it.next() for it in iterables]
args = [next(it) for it in iterables]
if function is None:
yield tuple(args)
else:
@ -404,11 +404,11 @@ loops that truncate the stream.
# islice('ABCDEFG', 0, None, 2) --> A C E G
s = slice(*args)
it = iter(xrange(s.start or 0, s.stop or sys.maxint, s.step or 1))
nexti = it.next()
nexti = next(it)
for i, element in enumerate(iterable):
if i == nexti:
yield element
nexti = it.next()
nexti = next(it)
If *start* is ``None``, then iteration starts at zero. If *step* is ``None``,
then the step defaults to one.
@ -738,8 +738,7 @@ which incur interpreter overhead.
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
for elem in b:
break
next(b, None)
return izip(a, b)
def grouper(n, iterable, fillvalue=None):