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


Groups > comp.lang.python > #80502

Re: "Natural" use of cmp= in sort

Newsgroups comp.lang.python
Date 2014-11-10 18:03 -0800
References <eb697764-934b-4650-af28-1c55520bc1da@googlegroups.com> <m3r34j$hb7$1@ger.gmane.org> <mailman.15631.1415648663.18130.python-list@python.org>
Message-ID <65bf2f6b-f83e-4900-ab6d-2dcdcbcb84b3@googlegroups.com> (permalink)
Subject Re: "Natural" use of cmp= in sort
From Paddy <paddy3118@gmail.com>

Show all headers | View raw


On Monday, 10 November 2014 19:44:39 UTC, Ian  wrote:
> On Mon, Nov 10, 2014 at 12:19 PM, Peter Otten <xxx@yyy> 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').

Thanks. I will look into this...

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