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 - 03:06:01 CEST

In article <mailman.4481.1144888259.27775.python-list@python.org>,
Peter Hansen <peter@engcorp.com> wrote:
>Alan Morgan wrote:
>> 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.
>
>If you know your basic python :-), you know that s[:] = [] is doing the
>only thing that s.clear() could possibly do,

Ah, but if you know your basic python then you wouldn't be looking for
s.clear() in the first place; you'd just use s[:]=[] (or s=[], whichever
is appropriate). IOW, the people most in need of s.clear() are those
least likely to be able to work out what it is actually doing.
Personally, it seems more *reasonable* to me, a novice python user,
for s.clear() to behave like s=[] (or, perhaps, for s=[] and s[:]=[] to
mean the same thing). The fact that it can't might be an argument for
not having it in the first place.

Alan

-- 
Defendit numerus
Received on Sun Apr 30 23:03:03 2006