[New-bugs-announce] [issue43899] separate builtin function
David Alvarez Lombardi
report at bugs.python.org
Tue Apr 20 17:47:05 EDT 2021
New submission from David Alvarez Lombardi <alvarezdqal at gmail.com>:
I frequently find myself doing the following for lists, sets, and dicts.
````
passes = [x for x in seq if cond(x)]
fails = [x for x in seq if not cond(x)]
````
The proposed function would behave similarly to `filter`, but it would return a tuple of the passes iterable and fails iterable rather than just the passes.
````
my_list = [-3, -2, -1, 0, 1, 2, 3]
def is_positive(n):
return n > 0
positives, negatives = separate(function=is_positive, iterable=my_list)
````
----------
messages: 391479
nosy: alvarezdqal
priority: normal
severity: normal
status: open
title: separate builtin function
type: enhancement
versions: Python 3.10
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43899>
_______________________________________
More information about the New-bugs-announce
mailing list