Looking for a different version of sort

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Tue Jun 15 22:32:43 EDT 2004


Brian McGonigle wrote:

> I'm a Perl programmer learning Python (up to chapter 7 in Learning
> Python, so go easy on me :-) and I find that I look to do things in
> Python the way I would do them in Perl. In Perl functions and methods
> usually only return and undefined value in the event of an error, make
> an endless number of compound statements possible. Is there a version
> of sort() I could import from somewhere that returns a reference to
> the object on which it was performed, rather than returning "None".

Python 2.4 includes `sorted` as a builtin which makes a copy of the
iterable passed, sorts it and returns it.

There is no function available which sorts in-place and returns a
reference to the list sorted, but it's very simple to write a function
to do it ...

def inplace_sort (l):
    l.sort()
    return l

Tim Delaney




More information about the Python-list mailing list