Partition list with predicate

Jared Grubb jared.grubb at
Wed Apr 23 21:08:44 EDT 2008

I guess I forgot one requirement: the removed elements need to be

Basically, I have a list of objects in a buffer, one class operates on some
of the objects, but other classes use others. So, a class must extract the
ones it can handle, and leave the rest in the buffer for the other classes
to handle.

I haven't found a function that will both remove objects from a list, but
save the ones that do get removed.


On 23 Apr 2008, at 10:15, Tim Golden wrote:

Jared Grubb wrote:

I want a function that removes values from a list if a predicate evaluates
to True. The best I could come up with is:

Have a look at the itertools module, and the ifilter function
in particular.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list