[Python-Dev] decorate-sort-undecorate
Barry Warsaw
barry at python.org
Wed Oct 15 15:25:32 EDT 2003
On Wed, 2003-10-15 at 13:52, Guido van Rossum wrote:
> > While we're hacking on [].sort(), how horrible would it be if we
> > modified it to return self instead of None?
>
> -1000. This is non-negotiable.
Sniff.
>>> class mylist(list):
... def sort(self, *args, **kws):
... super(mylist, self).sort(*args, **kws)
... return self
...
>>> mylist([5, 4, 3, 2, 1])
[5, 4, 3, 2, 1]
>>> x = mylist([5, 4, 3, 2, 1])
>>> x.sort()
[1, 2, 3, 4, 5]
Bliss.
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 307 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/python-dev/attachments/20031015/d011f721/attachment.bin
More information about the Python-Dev
mailing list