Skip to content

Allow False to be passed to filter #70027

Closed

Description

@leewz
mannequin
BPO 25840
Nosy @bitdancer, @leewz, @Vgr255

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2015-12-11.15:45:34.289>
created_at = <Date 2015-12-11.15:02:00.929>
labels = ['type-feature']
title = 'Allow `False` to be passed to `filter`'
updated_at = <Date 2015-12-11.19:54:59.059>
user = 'https://github.com/leewz'

bugs.python.org fields:

activity = <Date 2015-12-11.19:54:59.059>
actor = 'leewz'
assignee = 'none'
closed = True
closed_date = <Date 2015-12-11.15:45:34.289>
closer = 'r.david.murray'
components = []
creation = <Date 2015-12-11.15:02:00.929>
creator = 'leewz'
dependencies = []
files = []
hgrepos = []
issue_num = 25840
keywords = []
message_count = 4.0
messages = ['256218', '256219', '256222', '256231']
nosy_count = 3.0
nosy_names = ['r.david.murray', 'leewz', 'abarry']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue25840'
versions = ['Python 3.6']

Activity

  1. leewz commented on Dec 11, 2015

    leewzmannequin
    MannequinAuthor

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

  2. Vgr255 commented on Dec 11, 2015

    Vgr255mannequin
    Mannequin

    Do you mean like 'filter(None, lst)' does?

  3. bitdancer commented on Dec 11, 2015

    @bitdancer
    Member

    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 :)

  4. leewz commented on Dec 11, 2015

    leewzmannequin
    MannequinAuthor

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

  5. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions