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


Groups > comp.lang.python > #97014

Re: sort help

From Paul Rubin <no.email@nospam.invalid>
Newsgroups comp.lang.python
Subject Re: sort help
Date 2015-09-22 19:40 -0700
Organization A noiseless patient Spider
Message-ID <87io71dfjy.fsf@jester.gateway.sonic.net> (permalink)
References <mailman.74.1442962283.28679.python-list@python.org>

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