Jared Grubb wrote:
That almost works, except that a predicate can have "memory". For
example, the predicate could be "extract every other object", which
doesn't care about the value of the object (so you cant remove them
later based on value!). Or your predicate might be "remove the first 5
ob
That almost works, except that a predicate can have "memory". For example,
the predicate could be "extract every other object", which doesn't care
about the value of the object (so you cant remove them later based on
value!). Or your predicate might be "remove the first 5 objects that are
even", wh
On Wed, Apr 23, 2008 at 9:08 PM, Jared Grubb <[EMAIL PROTECTED]> wrote:
> I guess I forgot one requirement: the removed elements need to be
> remembered.
>
> 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
I guess I forgot one requirement: the removed elements need to be
remembered.
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 cl
On Apr 23, 2:26 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> Terry Reedy wrote:
> > "Jared Grubb" <[EMAIL PROTECTED]> wrote in message
> >news:[EMAIL PROTECTED]
> > | I want a function that removes values from a list if a predicate
> > evaluates
> > | to True.
>
> > Forget the rigamarole you poste
Terry Reedy wrote:
"Jared Grubb" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| I want a function that removes values from a list if a predicate
evaluates
| to True.
Forget the rigamarole you posted, which has several defects.
If you must modify the list in place, because you ha
"Jared Grubb" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| I want a function that removes values from a list if a predicate
evaluates
| to True.
Forget the rigamarole you posted, which has several defects.
If you must modify the list in place, because you have multiple referenc
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.
TJG
--
http://mail.python.org/mailman/listinfo/python-list
I want a function that removes values from a list if a predicate evaluates
to True. The best I could come up with is:
def extract(lst, pred):
idx = 0
ret = []
for obj in lst[:]:
if pred(obj):
ret.append(obj)
lst.pop(idx)
else:
idx +=