python equivalent of filter() getting two output lists
Posted
by
FX
on Stack Overflow
See other posts from Stack Overflow
or by FX
Published on 2011-01-02T13:34:11Z
Indexed on
2011/01/02
13:53 UTC
Read the original article
Hit count: 155
Let's say I have a list, and a filtering function. Using something like
>>> filter(lambda x: x > 10, [1,4,12,7,42])
[12, 42]
I can get the elements matching the criterion. Is there a function I could use that would output two lists, one of elements matching, one of the remaining elements? I could call the filter()
function twice, but that's kinda ugly :)
Edit: the order of elements should be conserved, and I may have identical elements multiple times.
© Stack Overflow or respective owner