Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97002
| Path | csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed7.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.028 |
| X-Spam-Evidence | '*H*': 0.94; '*S*': 0.00; 'subject:help': 0.07; 'sub': 0.09; 'def': 0.13; 'clear.': 0.16; 'pythonic': 0.16; 'sorting': 0.16; 'to:name:python-list@python.org': 0.20; '(a)': 0.22; 'this:': 0.23; 'second': 0.24; 'sort': 0.25; 'figure': 0.27; 'message-id:@mail.gmail.com': 0.27; 'this.': 0.28; 'initial': 0.28; 'field,': 0.30; "i'd": 0.31; 'another': 0.32; "can't": 0.32; 'common': 0.33; 'lists': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'quite': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'data': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'field': 0.60; 'hope': 0.61; 'show': 0.62 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=dQOQLzn3IG1xkLUcqcHjcgSTPeYEiHdk8yCmwxepWhI=; b=KvTk8YSdJ0E19gS4Ia3wP5IvCHDqJ6bjiiO3S9B/UBoXU1pDn4hcgGr1oNb360XdNr dSYqMskICWkCHAeNdV08OokIi8FIPu/f64tiWwoTT6jg03UEO+93x8xsi74B/bKPiiOU DWzWZe45ZGKHHmn3ma3E2XturPfTxee9jmHLGG/ViViVvXq5DAxy51eQPeGAa6MIEg7W +I+KaPmoi0pJmIhm+C3aT6xolJV3sokCSH2jJAfdlRh/mojFu3EeeowX4hztnh+HQbLa 5fsnG9lqsGVF4iztRC1ypIwBumMfAJd3b2dhBn76I2xIFRS1Rt+0WsL/mOHA4JkMSAoI uGHg== |
| MIME-Version | 1.0 |
| X-Received | by 10.55.204.66 with SMTP id r63mr32282324qki.10.1442961775526; Tue, 22 Sep 2015 15:42:55 -0700 (PDT) |
| Date | Tue, 22 Sep 2015 18:42:55 -0400 |
| Subject | 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.74.1442962283.28679.python-list@python.org> (permalink) |
| Lines | 45 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1442962283 news.xs4all.nl 23766 [2001:888:2000:d::a6]:41284 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:97002 |
Show key headers only | View raw
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.
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)
a[1, 4]
a[1, 2]
a[2, 3]
a[2, 1]
a[5, 6]
a[5, 2]
b[2]
b[5]
c[1]
c[6]
Then I'd want my sorted list to be this:
a[1,2]
a[1,4]
c[1]
a[2,1]
a[2,3]
b[2]
a[5,2]
a[5,6]
b[5]
c[6]
I hope that's clear.
So is there some pythonic way to sort this without resorting to a
brute force old fashioned plow through the data?
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll 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