Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80480

Re: "Natural" use of cmp= in sort

References <eb697764-934b-4650-af28-1c55520bc1da@googlegroups.com> <m3r34j$hb7$1@ger.gmane.org>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2014-11-10 12:43 -0700
Subject Re: "Natural" use of cmp= in sort
Newsgroups comp.lang.python
Message-ID <mailman.15631.1415648663.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Nov 10, 2014 at 12:19 PM, Peter Otten <__peter__@web.de> wrote:
> I'm not sure this works. I tried:

Here's a simpler failure case.

>>> ineq = """f2 > f3
... f3 > f1"""

[Previously posted code elided]

>>> greater_thans
set([('f3', 'f1'), ('f2', 'f3')])
>>> sorted(all_f, cmp=lambda t1, t2: 0 if t1==t2 else
...             (1 if (t1, t2) not in greater_thans else -1))
['f1', 'f2', 'f3']

Note that the greater_thans set is missing the implication by
transitivity that f2 > f1, so the given cmp function would
inconsistently return -1 for both comparisons cmp('f1', 'f2') and
cmp('f2', 'f1').

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

"Natural" use of cmp= in sort Paddy <paddy3118@gmail.com> - 2014-11-10 10:45 -0800
  Re: "Natural" use of cmp= in sort Peter Otten <__peter__@web.de> - 2014-11-10 20:19 +0100
  Re: "Natural" use of cmp= in sort Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-10 12:43 -0700
    Re: "Natural" use of cmp= in sort Paddy <paddy3118@gmail.com> - 2014-11-10 18:03 -0800
  Re: "Natural" use of cmp= in sort Paddy <paddy3118@gmail.com> - 2014-11-10 19:09 -0800
    Re: "Natural" use of cmp= in sort Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-10 23:36 -0700
      Re: "Natural" use of cmp= in sort Paddy <paddy3118@gmail.com> - 2014-11-10 23:44 -0800
        Re: "Natural" use of cmp= in sort Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-11 01:35 -0700
          Re: "Natural" use of cmp= in sort Paddy <paddy3118@gmail.com> - 2014-11-11 01:21 -0800
            Re: "Natural" use of cmp= in sort Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-11 10:59 -0700
              Re: "Natural" use of cmp= in sort Paddy <paddy3118@gmail.com> - 2014-11-12 00:09 -0800

csiph-web