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


Groups > comp.lang.python > #97003

Re: sort help

References <CACwCsY71moXc+72Y5CT6B2+_8d8cPNFyq7zG49STYWcZ5gfkEA@mail.gmail.com>
Date 2015-09-23 08:55 +1000
Subject Re: sort help
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.75.1442962527.28679.python-list@python.org> (permalink)

Show all headers | 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