Re: stupid/style/list question

2008-01-09 Thread Duncan Booth
[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 influen

Re: stupid/style/list question

2008-01-09 Thread bearophileHUGS
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.

Re: stupid/style/list question

2008-01-09 Thread Duncan Booth
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 s

Re: stupid/style/list question

2008-01-08 Thread Raymond Hettinger
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[:] = [

Re: stupid/style/list question

2008-01-08 Thread Giampaolo Rodola'
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

Re: stupid/style/list question

2008-01-08 Thread Tim Chase
> 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 thi

Re: stupid/style/list question

2008-01-08 Thread Fredrik Lundh
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 mos

stupid/style/list question

2008-01-08 Thread Giampaolo Rodola'
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