Em Ter, 2006-04-11 às 10:42 -0600, Steven Bethard escreveu: > one of:: > > del lst[:] > > lst[:] = [] > > or if you don't need to modify the list in place, > > lst = [] > > Personally, I tend to go Fredrik's route and use the first.
I love benchmarks, so as I was testing the options, I saw something very strange: $ python2.4 -mtimeit 'x = range(100000); ' 100 loops, best of 3: 6.7 msec per loop $ python2.4 -mtimeit 'x = range(100000); del x[:]' 100 loops, best of 3: 6.35 msec per loop $ python2.4 -mtimeit 'x = range(100000); x[:] = []' 100 loops, best of 3: 6.36 msec per loop $ python2.4 -mtimeit 'x = range(100000); del x' 100 loops, best of 3: 6.46 msec per loop Why the first benchmark is the slowest? I don't get it... could someone test this, too? Cheers, -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list