[Python-Dev] itertools predicates

Francisco Couzo franciscouzo at gmail.com
Thu Nov 3 12:10:51 EDT 2016


Stephen, dropwhile(None, ...) was an example, takewhile(None, ...) doesn't
works either and it makes a lot of sense IMO.

On Thu, Nov 3, 2016 at 7:07 AM, Stephen J. Turnbull <
turnbull.stephen.fw at u.tsukuba.ac.jp> wrote:

> Francisco Couzo writes:
>
>  > I'd be interested in writing a patch to make itertools more consistent
> if
>  > there's a consensus.
>
> I don't understand what you mean by "consistent".  I would argue that
> in Python, an argument of None means "use the TOOWTDI default".  For
> "filterfalse", bool() is pretty obvious for the default predicate
> since most Python classes do have a boolean interpretation.  For
> "groupby", I guess the identity is the "intuitive" default.  But for
> dropwhile, bool() or the identity seem like obvious choices, but
> intuitively they're not very useful since the head of what's left is a
> false-y.  When would you want that?  Typically false-ies are "nothing
> to see here, people, move along" values.  I guess that consideration
> suggest lambda x: not(x), but I don't see why one would want to spell
> that dropwhile(None, ...) rather than dropwhile(not, ...), especially
> since in many contexts what you might really want (and expect None to
> default to) is dropwhile(lambda x: x is None, ...).
>
> Bottom line for me is that this use (and non-use) of None is consistent
> with Python practice regarding defaults.
>
> So, "accepts None" vs "doesn't accept None" doesn't seem to me to be
> an important enough consistency to impose unobvious semantics on
> dropwhile(None, ...).
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20161103/f0076c53/attachment.html>


More information about the Python-Dev mailing list