list partition

Moosebumps Moosebumps at Moosebumps.Moosebumps
Sat Feb 21 23:37:44 CET 2004

Is there a function that takes a list and predicate, and returns two
lists -- one for which the predicate is true and one for which it is false?

I know I can call filter(p, list) and filter( not p, list) or something like
that, but I assume it would be more efficient to do it in one pass.

Actually I probably can't call "not p", I would have to wrap p in a function
notP or something.  Or is there a shortcut for lambda(x) : not p(x)?  I
guess it isn't that long : )


More information about the Python-list mailing list