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


Groups > comp.lang.python > #97014

Re: sort help

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Paul Rubin <no.email@nospam.invalid>
Newsgroups comp.lang.python
Subject Re: sort help
Date Tue, 22 Sep 2015 19:40:01 -0700
Organization A noiseless patient Spider
Lines 16
Message-ID <87io71dfjy.fsf@jester.gateway.sonic.net> (permalink)
References <mailman.74.1442962283.28679.python-list@python.org>
Mime-Version 1.0
Content-Type text/plain
Injection-Info mx02.eternal-september.org; posting-host="b061f73cef760cb35224bce5e09434e2"; logging-data="22866"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+3sxfIJyE4SuAgc9Lm+VVF"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)
Cancel-Lock sha1:u3pDPHmX0/Em63Oub3FEvPLrdf0= sha1:wpX4WHEMU+/UHYmGnQh5sJM4RTU=
Xref csiph.com comp.lang.python:97014

Show key headers only | View raw


Larry Martell <larry.martell@gmail.com> writes:
>         def GetObjKey(a):
>             return a[2]

This function is called operator.itemgetter:

    from operator import itemgetter
    sorted(a + b + c, key=itemgetter(2))

> So for example, if my initial data was this (I'll only show the fields
> involved with the sort - the first number is a[2] above and the second
> is the new additional sorting field, only present in a)

  sorted(sorted(a, key=itemgetter(5)) + b + c, key = itemgetter(2))

or whatever the new field (instead of 5) is for a.

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


Thread

sort help Larry Martell <larry.martell@gmail.com> - 2015-09-22 18:42 -0400
  Re: sort help Paul Rubin <no.email@nospam.invalid> - 2015-09-22 19:40 -0700

csiph-web