2.3 list reverse() bug?

Alex Martelli aleax at aleax.it
Sun Dec 28 04:57:40 EST 2003


Paul Rubin wrote:

> Andrew MacIntyre <andymac at bullseye.apana.org.au> writes:
>> > list(x) is my favourite way to make a shallow copy of list x, but x[:]
>> > and copy.copy(x) are essentially equivalent.
>> 
>> Behaviourally yes, performance wise no.
> 
> Eh?  Last time I looked at the copy module, x[:] is exactly what it did.

copy.copy(x) will have two extra name look-ups at the start (one for
the outer 'copy' name, one for the 'copy' name inside the module), a
function call, and inside that function a type(x) and a dispatch via
a type-to-function dictionary.  list(x) has roughly similar overhead.
Apparently, these miniscule extra bits of overhead appear to be enough
for Andrew to reject the "essentially equivalent" evaluation.


Alex





More information about the Python-list mailing list