[Tutor] Re: Re: list method sort()

Tim Peters tim.one at comcast.net
Fri Apr 2 15:28:23 EST 2004


[Andrei]
> Well, yes, you can argue that *all* operations which modify in-place
> should return the modified object as well - I don't know if this
> would be better or not: ...

Life would be hell in interactive Python shells if these things *didn't*
return None:

>>> somelist.sort()

Oops!  Nobody wants to sit and wait for an arbitrary amount of output then.
Very early versions of Python *also* displayed the result of non-None
expressions when running from .py files too, and then the only way to
suppress mountains of unwanted output would have been to do something like:

    dummy = somelist.sort()

Against my better judgment, Python 2.4 is adding a sorted() function to the
builtins, to stop people whining about this particular case.  That's against
my wishes because bloating the builtins with functions that are trivially
written in one or two lines bloats the builtins with functions that are
trivially written in one or two lines <wink>.




More information about the Tutor mailing list