"Natural" use of cmp= in sort

Ian Kelly ian.g.kelly at gmail.com
Tue Nov 11 18:59:00 CET 2014

On Tue, Nov 11, 2014 at 2:21 AM, Paddy <paddy3118 at gmail.com> wrote:
> On Tuesday, 11 November 2014 09:07:14 UTC, Ian  wrote:
>> On Tue, Nov 11, 2014 at 12:44 AM, Paddy <paddyxxx-at-xmail.com> wrote:
>> > Thanks Ian. The original author states "...and it is sure that the given inputs will give an output, i.e., the inputs will always be valid.", which could be taken as meaning that all inputs are sufficient, well formed, and contain all relations as their first example does.
>> Well, I brought it up because the start of that sentence is "There can
>> be multiple inequalities as answer but I need any one which is
>> correct...". The only way there would be more than one correct answer
>> would be if the inputs were only partially ordered. I take the second
>> part of the sentence as meaning only that the input can be safely
>> assumed to be consistent.
>> > Yes, I knew that there are cases where a cmp function is more natural than key; the idea is to squirrel out a few. We have already made the, (well reasoned in my opinion), decision to go down the key= route in Python 3. I also like to track where my algorithms might originally map to cmp=. (It is not often).
>> Basically any time you have a comparison that isn't easily expressed
>> by mapping the values to some bunch of ordered objects.
> Yep. I want to track when this comes up for me and others during their normal programming rather than in examples made to highlight the issue.

The example that I posted is one that I recall being brought up on
this list in the past, but I don't have a link for you.

More information about the Python-list mailing list