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


Groups > comp.lang.python > #97003

Re: sort help

X-FeedAbuse http://nntpfeed.proxad.net/abuse.pl feeded by 195.154.70.45
Path csiph.com!news.swapon.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!proxad.net!feeder1-2.proxad.net!nntpfeed.proxad.net!news.redatomik.org!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:help': 0.07; 'cc:addr:python-list': 0.09; 'stable.': 0.09; 'sub': 0.09; 'python': 0.10; 'def': 0.13; 'wed,': 0.15; 'explicitly': 0.15; '23,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'merge,': 0.16; 'sorting': 0.16; 'worst': 0.16; 'wrote:': 0.16; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '(a)': 0.22; 'sep': 0.22; 'am,': 0.23; 'this:': 0.23; 'tried': 0.24; 'header:In-Reply-To:1': 0.24; 'sort': 0.25; 'figure': 0.27; 'message-id:@mail.gmail.com': 0.27; 'this.': 0.28; 'larry': 0.29; 'another': 0.32; "can't": 0.32; 'common': 0.33; 'case,': 0.34; 'lists': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'quite': 0.35; 'but': 0.36; 'should': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'doing': 0.38; 'field': 0.60; 'your': 0.60; 'guaranteed': 0.67; 'chrisa': 0.84; 'comparable': 0.84; 'to:none': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=Keq2E5PNGScc4DQkCtW6k0vKOJUAKT2eZRn3upJWULM=; b=xO5/oS72kED3dODiQZ9XUIsU0D7RzjCsa9+HG1KA54+gIGE/CdsEQeY/jv8mv3Teto SqPt2SPKqubT6SmOXeLGr/u/J1liGOtyx4H8c99DltlqOusQr+6cGJsK1F/aGL1/VOhF yxQUkH9T/ys35ZZi04akOj/QOEz215AAmLh6IuWsTfi0CcC7DYg/GY0Ok0qH5dbaUR3K j8G/gfgxl3ro9RvTsi8o7HYQJwOieAphslDFdv4CVDGVjkQbEMw8t3kpOg6kQIB+4BCv 1FTETc+pDzUq2XurAx+0D0QvZ7ovGrdeef6JKXr/X2eW3wYW1mUiUiagnl8f89EYz6K2 SueA==
MIME-Version 1.0
X-Received by 10.50.50.198 with SMTP id e6mr20042356igo.13.1442962524395; Tue, 22 Sep 2015 15:55:24 -0700 (PDT)
In-Reply-To <CACwCsY71moXc+72Y5CT6B2+_8d8cPNFyq7zG49STYWcZ5gfkEA@mail.gmail.com>
References <CACwCsY71moXc+72Y5CT6B2+_8d8cPNFyq7zG49STYWcZ5gfkEA@mail.gmail.com>
Date Wed, 23 Sep 2015 08:55:24 +1000
Subject Re: sort help
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.75.1442962527.28679.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1442962527 news.xs4all.nl 23820 [2001:888:2000:d::a6]:44801
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:97003

Show key headers only | View raw


On Wed, Sep 23, 2015 at 8:42 AM, Larry Martell <larry.martell@gmail.com> wrote:
> I currently have 3 lists of lists and I sort them based on a common
> field into a single list like this:
>
>         def GetObjKey(a):
>             return a[2]
>
>         sorted(a + b + c, key=GetObjKey)
>
> Which works just fine.
>
> But now, I need to have just the first list (a) also sub sorted by
> another field and I can't quite figure out how to do this.

Have you tried simply sorting a by the other field prior to doing your
merge-and-sort? The Python list.sort() method is guaranteed to be
stable. I can't find a comparable guarantee for sorted(), but worst
case, you should be able to do your list merge, and then explicitly
name it and sort it.

ChrisA

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


Thread

Re: sort help Chris Angelico <rosuav@gmail.com> - 2015-09-23 08:55 +1000

csiph-web