emptying a list
Jon Clements
joncle at googlemail.com
Thu Oct 1 12:43:58 EDT 2009
On 1 Oct, 16:30, "lallous" <lall... at lgwm.org> 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.
More information about the Python-list
mailing list