Better solution

holger krekel pyth at devel.trillke.net
Tue Aug 20 15:37:28 EDT 2002


Michael Hudson wrote:
> holger krekel <pyth at devel.trillke.net> writes:
> 
> > > If you want to mutate the list, I'd say:
> > > 
> > > lst[:] = filter(None, lst)
> > > 
> > > is better than the monstrosity above.
> > 
> > why the '[:]'? 
> > 
> > doesn't seem to make any difference here unless
> > filter is allowed to return the same lst-object.
> 
> It depends whether you want to change the acutal list object or merely
> have 'lst' refer to a changed list.  Bo was using .pop in his
> question, so it's possible he wanted the former.

Aehem. i must be missing something obvious. 

Yes, append/sort/pop and friends are inplace-methods.

But isn't 

    filter(None,lst) 

supposed to return a new list? 

somebody is missing something here :-)

    holger




More information about the Python-list mailing list