[issue44571] itertools: takedowhile()

Raymond Hettinger report at bugs.python.org
Fri Jul 9 18:31:53 EDT 2021


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

> For convenience, the takewhile iterator can also have
> additional attributes: a boolean attribute which indicates 
> that the falsifying element is set, and dynamic attribute 
> which is equal to orig_iterator 
> or chain([odd_element], orig_iterator).

Rather than graft a funky and atypical API onto takewhile(), it would be better to have a new tool that returns two iterators, the true steam, and a stream for the remaining values.  Either stream may be empty.  There is no need for a boolean flag attribute or a remaining stream attribute.  This design fits in better with the other itertools.

FWIW, we can already do this using groupby(), but it is only easy if we assume the first part of the stream is all true and the remainder of the stream is all false.  That isn't good enough for general application.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44571>
_______________________________________


More information about the Python-bugs-list mailing list