On Mar 8, 1:49 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Fri, 07 Mar 2008 09:39:05 -0200, <[EMAIL PROTECTED]> > escribi�: > > > Executive summary : What idiom do you use for resetting a list ? > > lst = |] # (1) > > lst[:] = [] # (2) > > del lst[:] # (3) > > (3) if I want to keep the same list else (1)
"resetting a list" is vague and dubious terminology. (1) abandons a reference to some object (which MAY be a list) and binds the name "lst" to a new empty list. (3) providing that the referred-to object is of a type that supports assigning to slices, removes the contents. (2) effects the same as (3) -- it's just slower to type, compile and execute. I would rewrite the advice to the OP as: Use (3) if and only if you have a justifiable need (not "want") to keep the same list. Cheers, John -- http://mail.python.org/mailman/listinfo/python-list