This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients ethan.furman, gvanrossum, josh.r, rhettinger, serhiy.storchaka, steven.daprano, terry.reedy, veky, xtreak
Date 2020-11-09.20:04:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1604952263.13.0.6948004846.issue35712@roundup.psfhosted.org>
In-reply-to
Content
> I assume you've been recommending this?

Not really, but it does come up and I've seen it in customer code more than once.

I do show people this:

    >>> data = [10.5, 3.27, float('Nan'), 56.1]
    >>> list(filter(isfinite, data))
    [10.5, 3.27, 56.1]
    >>> list(filterfalse(isnan, data))
    [10.5, 3.27, 56.1]

The question does arise about how to do this for None using functional programming.  The answer is a bit awkward:

    >>> from operator import is_not
    >>> from functools import partial
    >>> data = [10.5, 3.27, None, 56.1]
    >>> list(filter(partial(is_not, None), data))
    [10.5, 3.27, 56.1]

From a teaching point of view, the important part is to show that this code does not do what people typically expect:

    >>> data = [10.5, 0.0, float('NaN'), 3.27, None, 56.1]
    >>> list(filter(None, data))
    [10.5, nan, 3.27, 56.1]

FWIW, this issue isn't important to me.  Just wanted to note that one of the idioms no longer works.  There are of course other ways to do it.
History
Date User Action Args
2020-11-09 20:04:23rhettingersetrecipients: + rhettinger, gvanrossum, terry.reedy, steven.daprano, ethan.furman, serhiy.storchaka, josh.r, veky, xtreak
2020-11-09 20:04:23rhettingersetmessageid: <1604952263.13.0.6948004846.issue35712@roundup.psfhosted.org>
2020-11-09 20:04:23rhettingerlinkissue35712 messages
2020-11-09 20:04:23rhettingercreate