Re: emptying a list
On Thu, Oct 1, 2009 at 10:13 PM, Jon Clements jon...@googlemail.com wrote: On 1 Oct, 16:30, lallous lall...@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 Is n't it y=x ? 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. -- http://mail.python.org/mailman/listinfo/python-list -- Yours, S.Selvam -- http://mail.python.org/mailman/listinfo/python-list
Re: emptying a list
lallous lall...@lgwm.org wrote in message news:ha2htc$u9...@aioe.org... 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: emptying a list
On 1 Oct, 16:30, lallous lall...@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. -- http://mail.python.org/mailman/listinfo/python-list
emptying a list
Hello What is faster when clearing a list? del L[:] or L = [] -- Elias -- http://mail.python.org/mailman/listinfo/python-list
Re: emptying a list
On Thu, Oct 1, 2009 at 11:30 AM, lallous lall...@lgwm.org 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. -- http://mail.python.org/mailman/listinfo/python-list