Re: list.clear() missing?!?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: list.clear() missing?!?

From: Alan Morgan <amorgan@xenon.Stanford.EDU>
Date: Thu Apr 13 2006 - 01:43:52 CEST

In article <pan.2006.04.12.23.23.07.830018@REMOVETHIScyber.com.au>,
Steven D'Aprano <steve@REMOVETHIScyber.com.au> wrote:
>On Wed, 12 Apr 2006 15:36:47 -0700, Alan Morgan wrote:
>
>> Serious question: Should it work more like "s=[]" or more like
>> "s[:]=[]". I'm assuming the latter, but the fact that there is
>> a difference is an argument for not hiding this operation behind
>> some syntactic sugar.
>
>Er, I don't see how it can possibly work like s = []. That merely
>reassigns a new empty list to the name s, it doesn't touch the existing
>list (which may or may not be garbage collected soon/immediately
>afterwards).

Right. I was wondering what would happen in this case:

s=[1,2,3]
t=s
s.clear()
t # [] or [1,2,3]??

If you know your basic python it is "obvious" what would happen
if you do s=[] or s[:]=[] instead of s.clear() and I guess it is
equally "obvious" which one s.clear() must mimic. I'm still not
used to dealing with mutable lists.

Alan

-- 
Defendit numerus
Received on Sun Apr 30 23:02:33 2006