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


Groups > comp.lang.python > #97038

Re: sort help

Path csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <larry.martell@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; 'merging': 0.07; 'subject:help': 0.07; '22,': 0.09; 'stable.': 0.09; 'sub': 0.09; 'python': 0.10; 'def': 0.13; 'wed,': 0.15; 'explicitly': 0.15; '23,': 0.16; 'hours/week.': 0.16; 'merge,': 0.16; 'simple.': 0.16; 'sorting': 0.16; 'worst': 0.16; 'wrote:': 0.16; '2015': 0.20; 'to:name:python-list@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; 'chris': 0.26; 'figure': 0.27; 'message- id:@mail.gmail.com': 0.27; 'this.': 0.28; 'larry': 0.29; 'that.': 0.30; 'probably': 0.31; 'everyone': 0.31; 'another': 0.32; "can't": 0.32; 'common': 0.33; 'case,': 0.34; 'tue,': 0.34; 'lists': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'quite': 0.35; 'but': 0.36; 'list,': 0.36; 'should': 0.36; 'to:addr:python- list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'thanks': 0.37; 'doing': 0.38; 'why': 0.39; 'sure': 0.39; "didn't": 0.39; 'to:addr:python.org': 0.40; 'field': 0.60; 'your': 0.60; 'guaranteed': 0.67; 'comparable': 0.84; 'replied.': 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:to :content-type; bh=D9sj9wy6pivYp+zqRPRVyRT92aLweT2bdN1bo6s53BE=; b=cAUWtv1O4V9NQ5uCGGgsODlYsbq4hqrrFRZHpZ1eDunR0YH2YQWARMc/Up99pPbs7d qViOsRtdPGL3b5xUGYzsObE0aHYNeA/+c8Ct4gIBfdAMv/eZXa1And5K5At8hoU9i+D+ BZ7lyQBVxHmW3JqzU9wraqxorAqPMcXekqQCHrJ0dpcKcHBWXBKkabcWOnHH0v2vMwvy kZzPEuImN2WzfO+NHAytf7hRs63o9tAwDN384TVPaNge7TqE05Jg3/KtnKkPPcXgVocA YmwEuwve4PwT/2Vu299/EznultZ9lS8S4iStzGqrCjooZIFJXNeCgn8gASMnxqB4Y3oK T+xw==
MIME-Version 1.0
X-Received by 10.140.152.68 with SMTP id 65mr36671515qhy.16.1443010894848; Wed, 23 Sep 2015 05:21:34 -0700 (PDT)
In-Reply-To <CAPTjJmrGj-aPYj7pS6zFcobRVj-OpM6oHq9q2OgC-RF+gG1b-A@mail.gmail.com>
References <CACwCsY71moXc+72Y5CT6B2+_8d8cPNFyq7zG49STYWcZ5gfkEA@mail.gmail.com> <CAPTjJmrGj-aPYj7pS6zFcobRVj-OpM6oHq9q2OgC-RF+gG1b-A@mail.gmail.com>
Date Wed, 23 Sep 2015 08:21:34 -0400
Subject Re: sort help
From Larry Martell <larry.martell@gmail.com>
To "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.103.1443010898.28679.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1443010898 news.xs4all.nl 23806 [2001:888:2000:d::a6]:36796
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:97038

Show key headers only | View raw


On Tue, Sep 22, 2015 at 6:55 PM, Chris Angelico <rosuav@gmail.com> wrote:
> 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.

Thanks to everyone for the replied. I ended up just presorting he
first list, then merging and sorting all 3. Very simple. Not sure why
I didn't see that. Probably comes from working 75 hours/week.

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


Thread

Re: sort help Larry Martell <larry.martell@gmail.com> - 2015-09-23 08:21 -0400

csiph-web