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


Groups > comp.lang.python > #97038 > unrolled thread

Re: sort help

Started byLarry Martell <larry.martell@gmail.com>
First post2015-09-23 08:21 -0400
Last post2015-09-23 08:21 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#97038 — Re: sort help

FromLarry Martell <larry.martell@gmail.com>
Date2015-09-23 08:21 -0400
SubjectRe: sort help
Message-ID<mailman.103.1443010898.28679.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web