On Thursday 02 April 2009 22:40:08 Zac Burns wrote: > Is it really worth it to not implement list.clear and answer this > question over and over again? > > I see no reason that a list shouldn't have a .clear method. > > -- > Zachary Burns > (407)590-4814 > Aim - Zac256FL > Production Engineer (Digital Overlord) > Zindagi Games > > On Thu, Apr 2, 2009 at 5:32 PM, Esmail <ebo...@hotmail.com> wrote: > > Emile van Sebille wrote: > >> Esmail wrote: > >>> Diez B. Roggisch wrote: > >>>> online.serv...@ymail.com schrieb: > >>>>> python's list needs a thing list.clear() like c# arraylist > >>>>> and > >>>> > >>>> some_list[:] = [] > >>> > >>> I agree that this is nice and clear, but as a relative newbie > >>> wouldn't > >>> > >>> some_list = [] > >> > >> This is different -- it creates a new list. Consider: > >> > >> >>> some_list = [1,2,3] > >> >>> d = some_list > >> >>> d[1] > >> 2 > >> >>> some_list[:] = ['a','b','c'] > >> >>> d[1] > >> 'b' > >> >>> some_list = [1,2,3] > >> >>> d[1] > >> 'b' > >> > >> the [:] form allows references into the list to remain valid while the > >> direct assignment dopes not. > > > > Ah .. thanks for clarifying this .. makes sense. > > > > Also, thank you Luis for your post. > > > > Esmail > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > -- > http://mail.python.org/mailman/listinfo/python-list
A .clear() method wouldn't be beneficial: del mylist[:] -- Armin Moradi -- http://mail.python.org/mailman/listinfo/python-list