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


Groups > comp.lang.python > #106424

Re: Sorting a list

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: Sorting a list
Date Mon, 04 Apr 2016 08:56:26 +0200
Organization None
Lines 23
Message-ID <mailman.2.1459753001.32530.python-list@python.org> (permalink)
References <ndrn97$bco$1@dont-email.me> <mailman.408.1459711883.28225.python-list@python.org> <ndrt29$36l$1@dont-email.me> <ndt36r$oi$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace news.uni-berlin.de g9Q2ZUla0O7o+S5ZFkEcNwcAdg9w2Phv00g1uAENEW/Q==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'string.': 0.04; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'intermediate': 0.15; 'dfs': 0.16; 'itemgetter': 0.16; 'lambda': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; 'input': 0.18; 'second': 0.24; 'import': 0.24; 'header:User-Agent:1': 0.26; 'subject:list': 0.26; 'header:X-Complaints-To:1': 0.26; 'print': 0.30; 'lists': 0.34; 'that,': 0.34; 'could': 0.35; "isn't": 0.35; 'skip:{ 10': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'thought': 0.37; 'why': 0.39; 'data': 0.39; 'well.': 0.40; 'to:addr:python.org': 0.40; 'received:de': 0.40; '>>>>>': 0.66; 'otten': 0.84
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host p57bd9cb3.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
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>
X-Mailman-Original-Message-ID <ndt36r$oi$1@ger.gmane.org>
X-Mailman-Original-References <ndrn97$bco$1@dont-email.me> <mailman.408.1459711883.28225.python-list@python.org> <ndrt29$36l$1@dont-email.me>
Xref csiph.com comp.lang.python:106424

Show key headers only | View raw


DFS wrote:

> On 4/3/2016 3:31 PM, Peter Otten wrote:

>>>>> from operator import itemgetter as get
>>>>> print "\n".join("{1} {0}".format(*p) for p in sorted(
>> ... sorted(colCounts, key=get(1)), key=get(0), reverse=True))
> 
> Kind of clunky looking.  Is that why don't you recommend it?

That, and you produce two intermediate lists and an intermediate string. For 
larger input data this may produce significant overhead.

>> You could also cheat and use
>>
>> lambda v: (-v[0], v[1])
>>
>> and a single sorted().
> 
> That works well.  Why is it 'cheating'?

On second thought it isn't ;)

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


Thread

Sorting a list DFS <nospam@dfs.com> - 2016-04-03 14:30 -0400
  Re: Sorting a list DFS <nospam@dfs.com> - 2016-04-03 14:34 -0400
  Re: Sorting a list Peter Otten <__peter__@web.de> - 2016-04-03 21:31 +0200
    Re: Sorting a list DFS <nospam@dfs.com> - 2016-04-03 16:08 -0400
      Re: Sorting a list Peter Otten <__peter__@web.de> - 2016-04-04 08:56 +0200
      Re: Sorting a list Random832 <random832@fastmail.com> - 2016-04-04 09:40 -0400
      Re: Sorting a list Peter Otten <__peter__@web.de> - 2016-04-04 16:12 +0200

csiph-web