Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

> 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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue35712>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to