Why list.sort() don't return the list reference instead of None?

Lawrence Oluyede raims at dot.com
Mon May 8 02:44:57 EDT 2006


"ankyhe at gmail.com" <ankyhe at gmail.com> writes:

> I want to ask why the designer of Python do so?

I'm not a Python core developer nor a designer but I've always known that
sort() is a in-place sort and since the list is a mutable object it mutates the
list sending the "sort()" message. If you want to get back a sorted iterable
use... sorted :)

L = [3, 1, 2]
ls = sorted(L)

now ls is your list, sorted.

-- 
Lawrence - http://www.oluyede.org/blog
"Nothing is more dangerous than an idea
if it's the only one you have" - E. A. Chartier



More information about the Python-list mailing list