[issue30346] Odd behavior when unpacking `itertools.groupby`

Raymond Hettinger report at bugs.python.org
Fri May 12 02:33:03 EDT 2017


Raymond Hettinger added the comment:

I suppose that when the input iterator is exhausted, we could poison the currkey to make the subordinate iterator ends as well:

    def __next__(self):
        while self.currkey == self.tgtkey:
            try:    
                self.currvalue = next(self.it)
            except StopIteration:
                self.currkey = object()
                raise StopIteration from None
            self.currkey = self.keyfunc(self.currvalue)
        self.tgtkey = self.currkey
        return (self.currkey, self._grouper(self.tgtkey))

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30346>
_______________________________________


More information about the Python-bugs-list mailing list