list.reverse()
Manuel M. Garcia
mgarcia at cole-switches.com
Fri Nov 15 21:53:09 EST 2002
On Fri, 15 Nov 2002 20:16:30 -0600, Mike Dean <klaatu at evertek.net>
wrote:
>I think I recall seeing a reasonable explanation for this earlier
>(probably referring actually to list.sort()), but I'm wondering - what
>was the rationale for making list.reverse() reverse a list in-place
>rather than return a new, reversed list? I'm sure there's a good
>reason, but what might that be?
list.reverse() is implemented as a very efficient, very tight C loop,
because it is just swapping a bunch of pointers to internal Python
objects. It requires much less time than having to make a copy,
especially since a Python object can have unlimited size and unlimited
levels of nesting of objects inside of objects.
Manuel
More information about the Python-list
mailing list