list.sort()

Nick Perkins nperkins7 at home.com
Sun Jun 17 21:22:31 CEST 2001


"Rikard Bosnjakovic" <bos at hack.org> wrote in message
...
> >>> l = l
...
I am pretty sure that
l = l
will never have any effect, whatsoever.
Assignment never creates a copy of the data, it just 'points' to the same
data.
( or "refers to the same object" )
This just makes l point to whatever it already points to.  No effect.


..however..

I do find it a bit strange that list.sort() returns None, but I am sure
there is a good reason for that.


It is also strange that you can legally do:
[3,2,5].sort()

..but you can not recover the sorted list.
eg.

a = [3,2,5].sort()
assert a == None

I presume that the list actually gets sorted, but since no referece is
maintained to the list, it immediately becomes 'garbage', and is lost
forever.


..the same goes for list.reverse()...

If they both returned references to themselves, you could do:
a = [3,2,5].sort().reverse()
assert a == [5,3,2]






More information about the Python-list mailing list