Creating a List of Empty Lists

Robin Becker robin at jessikat.fsnet.co.uk
Tue Dec 9 07:52:10 EST 2003


In article <Xns944C79E1BBF8Dduncanrcpcouk at 127.0.0.1>, Duncan Booth
<duncan at NOSPAMrcp.co.uk> writes
....
>You obviously think something was wrong with my earlier timings, but I 
>can't understand from this what the problem was; timeit.py does some 
>reasonably clever things to try to give an accurate answer including 
>varying the number of times it repeats the test to ensure that the time per 
>loop is based on a reasonably large time interval.
>
not at all, I was puzzled by the reversal of earlier stuff. You're right
about the comprehension as well, I had thought the variable was
internal, but making it local gives the comprehension the edge.

C:\tmp>\python23\python ttt.py
list ()              = 1.72
list []              = 3.27
comprehension        = 0.81
copy                 = 3.94
cCopy.copy           = 1.59
lambda z: z[:]       = 1.14
lambda z: list(z)    = 4.73
lambda z: []         = 0.95
f=lambda z: []       = 0.95

like /F though I am extremely puzzled about the list result. 
-- 
Robin Becker




More information about the Python-list mailing list