8000 Allow `False` to be passed to `filter` · Issue #70027 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Allow False to be passed to filter #70027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
leewz mannequin opened this issue Dec 11, 2015 · 4 comments
Closed

Allow False to be passed to filter #70027

leewz mannequin opened this issue Dec 11, 2015 · 4 comments
Labels
type-feature A feature request or enhancement

Comments

@leewz
Copy link
Mannequin
leewz mannequin commented Dec 11, 2015
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']

@leewz
Copy link
Mannequin Author
leewz mannequin commented Dec 11, 2015

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

@leewz leewz mannequin added the type-feature A feature request or enhancement label Dec 11, 2015
@Vgr255
Copy link
Mannequin
Vgr255 mannequin commented Dec 11, 2015

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

@bitdancer
Copy link
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 :)

@leewz
Copy link
Mannequin Author
leewz mannequin commented Dec 11, 2015

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

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant
0