Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > emptying a list

Reply
Thread Tools

emptying a list

 
 
lallous
Guest
Posts: n/a
 
      10-01-2009
Hello

What is faster when clearing a list?

del L[:]

or

L = []

--
Elias
 
Reply With Quote
 
 
 
 
Geoffrey Clements
Guest
Posts: n/a
 
      10-01-2009
"lallous" <(E-Mail Removed)> wrote in message news:ha2htc$u9u$(E-Mail Removed)...
> Hello
>
> What is faster when clearing a list?
>
> del L[:]
>
> or
>
> L = []
>


Oh, "L = []" definitely, on the basis that there are fewer characters to
type.


http://docs.python.org/3.1/library/profile.html

--
Geoff


 
Reply With Quote
 
 
 
 
Jon Clements
Guest
Posts: n/a
 
      10-01-2009
On 1 Oct, 16:30, "lallous" <(E-Mail Removed)> wrote:
> Hello
>
> What is faster when clearing a list?
>
> del L[:]
>
> or
>
> L = []
>
> --
> Elias


Does it really matter that much?

And you're really talking about two different things, which quite
often come up on this group.

Example follows:

>>> x = range(5)
>>> x = y
>>> print x, y

[1, 2, 3, 4] [1, 2, 3, 4]
>>> x = []
>>> print x, y

[] [1, 2, 3, 4]
>>> x = y
>>> print x, y

[1, 2, 3, 4] [1, 2, 3, 4]
>>> del x[:]
>>> print x, y

[] []

Cheers,
Jon.
 
Reply With Quote
 
Simon Forman
Guest
Posts: n/a
 
      10-02-2009
On Thu, Oct 1, 2009 at 11:30 AM, lallous <(E-Mail Removed)> wrote:
> Hello
>
> What is faster when clearing a list?
>
> del L[:]
>
> or
>
> L = []
>
> --
> Elias
> --
> http://mail.python.org/mailman/listinfo/python-list
>


The first form actually clears the list, the second for just re-binds
the name 'L' to a new, empty list.
 
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
Emptying the cache for the entire ASP.NET site Daren ASP .Net 0 12-19-2005 08:32 PM
cached backed or self-emptying map Wendy Smoak Java 2 04-29-2005 12:09 AM
Re: emptying deleted items Michael Thompson Computer Support 0 06-23-2003 01:52 AM
Re: emptying deleted items Alison Jones Computer Support 0 06-23-2003 12:27 AM
Re: emptying deleted items °Mike° Computer Support 0 06-23-2003 12:08 AM



Advertisments