[Python-ideas] suggestion about the sort() function of the list instance
Stephan Houben
stephanh42 at gmail.com
Wed Mar 1 05:10:12 EST 2017
It's even in the Programming FAQ:
"In general in Python (and in all cases in the standard library) a method
that mutates an object will return None to help avoid getting the two types
of operations confused. So if you mistakenly write y.sort() thinking it
will give you a sorted copy of y, you’ll instead end up with None, which
will likely cause your program to generate an easily diagnosed error."
Stephan
2017-03-01 10:31 GMT+01:00 Paul Moore <p.f.moore at gmail.com>:
> On 1 March 2017 at 01:31, qhlonline <qhlonline at 163.com> wrote:
> > My code example is not proper, Yes, may be this is better:
> > list.sort().revers(
>
> We can already do this - reversed(sorted(lst))
>
> This is a long-established design decision in Python. It would need a
> *very* compelling use case to even think about changing it.
> Paul
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170301/1715d439/attachment.html>
More information about the Python-ideas
mailing list