Better solution

Michael Hudson mwh at python.net
Tue Aug 20 18:49:29 CEST 2002


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.

Cheers,
M.

-- 
  There's a difference between random people with stripy jumpers, 
  and a respected scientist with a reputation.
                                            -- Steve Kitson, ucam.chat



More information about the Python-list mailing list