Fredrik Lundh [EMAIL PROTECTED] wrote:
Giampaolo Rodola' wrote:
To flush a list it is better doing del mylist[:] or mylist = []?
Is there a preferred way? If yes, why?
The latter creates a new list object, the former modifies an existing
list in place.
The latter is shorter, reads
Duncan Booth:
I tried to measure this with timeit, and it looks like the 'del' is
actually quite a bit faster (which I find suprising).
Yes, it was usually faster in my benchmarks too. Something similar is
true for dicts too. I think such timings are influenced a lot by the
garbage collector.
[EMAIL PROTECTED] wrote:
Duncan Booth:
I tried to measure this with timeit, and it looks like the 'del' is
actually quite a bit faster (which I find suprising).
Yes, it was usually faster in my benchmarks too. Something similar is
true for dicts too. I think such timings are influenced a
Giampaolo Rodola' wrote:
To flush a list it is better doing del mylist[:] or mylist = []?
Is there a preferred way? If yes, why?
The latter creates a new list object, the former modifies an existing
list in place.
The latter is shorter, reads better, and is probably a bit faster in
most
I was wondering...
To flush a list it is better doing del mylist[:] or mylist = []?
Is there a preferred way? If yes, why?
--
http://mail.python.org/mailman/listinfo/python-list
To flush a list it is better doing del mylist[:] or mylist = []?
Is there a preferred way? If yes, why?
It depends on what you want. The former modifies the list
in-place while the latter just reassigns the name mylist to
point to a new list within the local scope as demonstrated by this:
On 8 Gen, 16:45, Fredrik Lundh [EMAIL PROTECTED] wrote:
Giampaolo Rodola' wrote:
To flush a list it is better doing del mylist[:] or mylist = []?
Is there a preferred way? If yes, why?
The latter creates a new list object, the former modifies an existing
list in place.
The latter is
On Jan 8, 7:34 am, Giampaolo Rodola' [EMAIL PROTECTED] wrote:
I was wondering...
To flush a list it is better doing del mylist[:] or mylist = []?
Is there a preferred way? If yes, why?
To empty an existing list without replacing it, the choices
are del mylist[:] and mylist[:] = []. Of the