"Natural" use of cmp= in sort
Paddy
paddy3118 at gmail.com
Mon Nov 10 21:03:07 EST 2014
More information about the Python-list mailing list
Mon Nov 10 21:03:07 EST 2014
- Previous message (by thread): "Natural" use of cmp= in sort
- Next message (by thread): "Natural" use of cmp= in sort
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Monday, 10 November 2014 19:44:39 UTC, Ian wrote: > On Mon, Nov 10, 2014 at 12:19 PM, Peter Otten <xxx at 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...
- Previous message (by thread): "Natural" use of cmp= in sort
- Next message (by thread): "Natural" use of cmp= in sort
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list