Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.044 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'works.': 0.09; 'posted': 0.15; 'cmp': 0.16; 'tried:': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'case.': 0.24; 'simpler': 0.24; 'mon,': 0.24; 'header:In-Reply- To:1': 0.27; 'function': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'received:google.com': 0.35; 'nov': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'subject:" ': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'otten': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=lWhFG+88uVJ5jx7GRvRAC9nGmYRrsYu5Ut28up2328U=; b=seCEvI2OuRrPz8+oUVVKcCk0pthISBOgc4RJLO3p4GY9/mxko2tMXYhR91dSm0KheZ C6X5jNG//27jilr5iRF9FsIJIBjBzwkZr6sMdFIbC2kj/uh0HIoTKtQbraep9Kmpjqjn mifGZB0X27BIfADbM4AFF6xQs4ursoHlm5oVtuY2F1dcaLB70AO8ztmSro4xM5K/oKpu PMhtcsUaCULiThMaiiP01hdn77O/Q3mNp90HSDFeTcjhEdKXN3yVoIutToIQ447ERPMv ZB3pe+CBbZPRy+P50pY2g36dMrNpUqHB+SSeDuabhqAczMRjIMr+3DnnIYQp7kWXlslz aeQg== X-Received: by 10.68.111.161 with SMTP id ij1mr34757887pbb.10.1415648660024; Mon, 10 Nov 2014 11:44:20 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Mon, 10 Nov 2014 12:43:39 -0700 Subject: Re: "Natural" use of cmp= in sort To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415648663 news.xs4all.nl 2883 [2001:888:2000:d::a6]:59197 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80480 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').