Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > python needs leaning stuff from other language

Reply
Thread Tools

python needs leaning stuff from other language

 
 
Zac Burns
Guest
Posts: n/a
 
      04-03-2009
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 <(E-Mail Removed)> wrote:
> Emile van Sebille wrote:
>>
>> Esmail wrote:
>>>
>>> Diez B. Roggisch wrote:
>>>>
>>>> http://www.velocityreviews.com/forums/(E-Mail Removed) 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
>

 
Reply With Quote
 
 
 
 
Terry Reedy
Guest
Posts: n/a
 
      04-03-2009
Diez B. Roggisch wrote:
> (E-Mail Removed) schrieb:
>> python's list needs a thing list.clear() like c# arraylist
>> and

>
> some_list[:] = []


Or
del some_list[:]

 
Reply With Quote
 
 
 
 
MRAB
Guest
Posts: n/a
 
      04-03-2009
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.
>

Does dict have a .clear method? Yes.

Does set have a .clear method? Yes.

Does list have a .clear method? No.

Of course, with a list you can do del my_list[:]; there's no simple
equivalent for dict or set.

But, overall, I'm +1.
 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      04-03-2009
On Thu, 02 Apr 2009 18:40:08 -0700, 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.



The usual answer to that is that there's already two ways of clearing a
list:

del alist[:]
alist[:] = []

and we don't need a third way. Dicts and sets need a clear() method,
because there's no equivalent to slicing.

I still think that alist.clear() would be a fine addition that matches my
intuition and aesthetic sense. Alas, I'm apparently not Dutch.


BTW Zac, on this list we don't appreciate top-posting, and we encourage
people to trim the quoted replies.



--
Steven
 
Reply With Quote
 
Zamnedix
Guest
Posts: n/a
 
      04-03-2009
On Apr 2, 3:25 pm, (E-Mail Removed) wrote:
> python's list needs a thing list.clear() like c# arraylist
> and
> python needs a writeline() method


Please don't post things like list before you do any research.
You don't know what you are talking about.
 
Reply With Quote
 
Mel
Guest
Posts: n/a
 
      04-03-2009
Ben Finney wrote:

> I think it would also be better to have One (and prefereably Only One)
> Obvious Way To Do It. That obvious way, for those who work with
> Python's ‘set’ and ‘dict’, is a ‘clear’ method. It seems best to have
> ‘list’ conform with this also.


Does that mean a one-off special case rule to forbid slices having a
default?

Mel.


 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      04-03-2009
On Fri, 03 Apr 2009 08:23:22 -0700, Zamnedix wrote:

> On Apr 2, 3:25 pm, (E-Mail Removed) wrote:
>> python's list needs a thing list.clear() like c# arraylist and
>> python needs a writeline() method

>
> Please don't post things like list before you do any research. You don't
> know what you are talking about.


The original poster may or may not know what he is talking about, but
adding a clear() method to lists seems to be very much in demand. I'd
vote Yes for one.

Besides, this news group is for people to ask questions about Python,
even stupid questions. It's not just for experts only.



--
Steven
 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      04-03-2009
On Fri, 03 Apr 2009 11:41:10 -0400, Mel wrote:

> Ben Finney wrote:
>
>> I think it would also be better to have One (and prefereably Only One)
>> Obvious Way To Do It. That obvious way, for those who work with
>> Python's ‘set’ and ‘dict’, is a ‘clear’ method. It seems best to have
>> ‘list’ conform with this also.

>
> Does that mean a one-off special case rule to forbid slices having a
> default?


Why would it do that?


--
Steven
 
Reply With Quote
 
Mel
Guest
Posts: n/a
 
      04-03-2009
Steven D'Aprano wrote:

> On Fri, 03 Apr 2009 11:41:10 -0400, Mel wrote:
>
>> Ben Finney wrote:
>>
>>> I think it would also be better to have One (and prefereably Only One)
>>> Obvious Way To Do It. That obvious way, for those who work with
>>> Python's ‘set’ and ‘dict’, is a ‘clear’ method. It seems best to have
>>> ‘list’ conform with this also.

>>
>> Does that mean a one-off special case rule to forbid slices having a
>> default?

>
> Why would it do that?


Well, if list.clear were truly and strictly to be the only way to clear the
contents of a list, then assigning nothing via the default slice would have
to be ruled out. `somelist[:] = []` is just a special case of assignment to
a slice generally.

Mel.


 
Reply With Quote
 
Tim Wintle
Guest
Posts: n/a
 
      04-03-2009
On Fri, 2009-04-03 at 13:12 -0400, Mel wrote:
> >>> I think it would also be better to have One (and prefereably Only One)
> >>> Obvious Way To Do It. That obvious way, for those who work with
> >>> Python's ‘set’ and ‘dict’, is a ‘clear’ method. It seems best to have
> >>> ‘list’ conform with this also.
> >>
> >> Does that mean a one-off special case rule to forbid slices having a
> >> default?

> >
> > Why would it do that?

>
> Well, if list.clear were truly and strictly to be the only way to clear the
> contents of a list, then assigning nothing via the default slice would have
> to be ruled out. `somelist[:] = []` is just a special case of assignment to
> a slice generally.


agreed. If .clear was to be added then really assignments to slices
should be entirely removed.

Tim W

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Left leaning red black trees Antoninus Twink C Programming 10 12-03-2009 01:31 PM
Leaning out Vista 64 a little? Don Windows 64bit 5 02-24-2008 11:18 PM
Is there any provisions for leaning difficulties in the mcse exams =?Utf-8?B?ZW5ncmhhcnY=?= Microsoft Certification 1 04-14-2005 10:02 AM
Long trip - Leaning towards Coolpix 8800 - PLEASE ADVISE! ggal Digital Photography 3 03-28-2005 11:26 PM
MONA LISA AND THE LEANING TOWER OF PIZZI Bendt Ten Brock Digital Photography 0 01-19-2004 11:32 AM



Advertisments