Re: Efficient way to remove objects from a list

2008-11-03 Thread 一首诗
Thanks! That's a more clear way! On Nov 3, 9:38 pm, Peter Otten <[EMAIL PROTECTED]> wrote: > Chris Rebert wrote: > > On Mon, Nov 3, 2008 at 1:40 AM, 一首诗 <[EMAIL PROTECTED]> wrote: > >> Hi all, > > >> Today I wrote some code like this: > > > Build a new list as you go, then overwrite the old list

Re: Efficient way to remove objects from a list

2008-11-03 Thread Peter Otten
Chris Rebert wrote: > On Mon, Nov 3, 2008 at 1:40 AM, 一首诗 <[EMAIL PROTECTED]> wrote: >> Hi all, >> >> Today I wrote some code like this: >> > > Build a new list as you go, then overwrite the old list with it. > > unfinished = [] > >>for m in self.messages: >>if not m.finishe

Re: Efficient way to remove objects from a list

2008-11-03 Thread Peter Otten
M.-A. Lemburg wrote: >> The typical way to do this is to iterate over the list in reverse >> order and then using the item index as basis for removing the >> item: >> >> for i, item in enumerate(reversed(mylist)): >> # process item >> del mylist[i] > > Sorry, the above should read: > >

Re: Efficient way to remove objects from a list

2008-11-03 Thread M.-A. Lemburg
On 2008-11-03 12:12, M.-A. Lemburg wrote: >> 一首诗 wrote: >>> Hi all, >>> >>> Today I wrote some code like this: >>> >>> for m in self.messages: >>> if not m.finished: >>> continue >>> >>> #process the message >>> >>> fini = [m for m in self.mes

Re: Efficient way to remove objects from a list

2008-11-03 Thread M.-A. Lemburg
> 一首诗 wrote: >> Hi all, >> >> Today I wrote some code like this: >> >> for m in self.messages: >> if not m.finished: >> continue >> >> #process the message >> >> fini = [m for m in self.messages if m.finished] >> for m in fini: >>

Re: Efficient way to remove objects from a list

2008-11-03 Thread Tino Wildenhain
一首诗 wrote: Hi all, Today I wrote some code like this: for m in self.messages: if not m.finished: continue #process the message fini = [m for m in self.messages if m.finished] for m in fini: self.messages.remove(m) As

Re: Efficient way to remove objects from a list

2008-11-03 Thread Chris Rebert
On Mon, Nov 3, 2008 at 1:40 AM, 一首诗 <[EMAIL PROTECTED]> wrote: > Hi all, > > Today I wrote some code like this: > Build a new list as you go, then overwrite the old list with it. unfinished = [] >for m in self.messages: >if not m.finished: unfinished.append(

Efficient way to remove objects from a list

2008-11-03 Thread 一首诗
Hi all, Today I wrote some code like this: for m in self.messages: if not m.finished: continue #process the message fini = [m for m in self.messages if m.finished] for m in fini: self.messages.remove(m) As you can, I w