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.

classification
Title: Allow `False` to be passed to `filter`
Type: enhancement Stage: resolved
Components: Versions: Python 3.6
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: abarry, leewz, r.david.murray
Priority: normal Keywords:

Created on 2015-12-11 15:02 by leewz, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg256218 - (view) Author: Franklin? Lee (leewz) Date: 2015-12-11 15:02
Meaning:

    filter(False, lst)
    == (x for x in lst if not x)
    == itertools.filterfalse(None, lst)

I understand that it is a very minor enhancement, and with not much benefit. I just happened to think about it, and wondered why it didn't already exist. I figured it wouldn't hurt to put the idea out here.

(If anyone is interested, I was looking into ways that filter/map/itertools could "unwrap" each other at the C level to improve composition of generators, inspired by the functools.partial optimization.)
msg256219 - (view) Author: Anilyka Barry (abarry) * (Python triager) Date: 2015-12-11 15:12
Do you mean like 'filter(None, lst)' does?
msg256222 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-12-11 15:45
I don't think it is worth adding as a special case.  Itertools has it because of what itertools is (a mini-language for manipulating iterables), but the legacy filter function has no reason to grow additional special cases beyond None.  (It's not even clear why it has that one special case :)
msg256231 - (view) Author: Franklin? Lee (leewz) Date: 2015-12-11 19:54
ebarry, note that `filter(None, lst)` is equivalent to `filter(bool, lst)`, which is the opposite of `filterfalse(None, lst)`. (Though `filter(True, lst) == filter(bool, lst)` would be a parallel.)
History
Date User Action Args
2022-04-11 14:58:24adminsetgithub: 70027
2015-12-11 19:54:59leewzsetmessages: + msg256231
2015-12-11 15:45:34r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg256222

resolution: rejected
stage: resolved
2015-12-11 15:12:58abarrysetnosy: + abarry
messages: + msg256219
2015-12-11 15:02:00leewzcreate