[Python-ideas] suggestion about the sort() function of the list instance

Stéfane Fermigier sf at fermigier.com
Wed Mar 1 05:26:00 EST 2017


Cf. https://martinfowler.com/bliki/CommandQuerySeparation.html

But:

>>> l = [1,2,3]
>>> l.pop()
3
>>> l
[1, 2]

=> Not so true.

  S.

On Wed, Mar 1, 2017 at 11:10 AM, Stephan Houben <stephanh42 at gmail.com>
wrote:

> 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/
>>
>
>
> _______________________________________________
> 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/
>



-- 
Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier -
http://linkedin.com/in/sfermigier
Founder & CEO, Abilian - Enterprise Social Software -
http://www.abilian.com/
Chairman, Free&OSS Group / Systematic Cluster -
http://www.gt-logiciel-libre.org/
Co-Chairman, National Council for Free & Open Source Software (CNLL) -
http://cnll.fr/
Founder & Organiser, PyData Paris - http://pydata.fr/
---
“You never change things by fighting the existing reality. To change
something, build a new model that makes the existing model obsolete.” — R.
Buckminster Fuller
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170301/0bbf59f5/attachment.html>


More information about the Python-ideas mailing list