Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: DFS Newsgroups: comp.lang.python Subject: Sorting a list Date: Sun, 3 Apr 2016 14:30:00 -0400 Organization: A noiseless patient Spider Lines: 40 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 3 Apr 2016 18:26:48 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="5399b1c4ae39fc7dd2f40cbc5f70036e"; logging-data="11672"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18yaVGO22cs+Ru9nM+Fw0Ht" User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 X-Mozilla-News-Host: news://news.eternal-september.org Cancel-Lock: sha1:g/8382ijF3uaeBagj+ybTikGIAc= Xref: csiph.com comp.lang.python:106387 cntText = 60 cntBool = 20 cntNbrs = 30 cntDate = 20 cntBins = 20 strText = " text: " strBool = " boolean: " strNbrs = " numeric: " strDate = " date-time:" strBins = " binary: " colCounts = [(cntText,strText) , (cntBool,strBool), (cntNbrs,strNbrs) , (cntDate,strDate) , (cntBins,strBins)] # sort by alpha, then by column type count descending colCounts.sort(key=lambda x: x[1]) colCounts.sort(key=lambda x: x[0], reverse=True) for key in colCounts: print key[1], key[0]] ------------------------------------------------- Output (which is exactly what I want): text: 60 numeric: 30 binary: 20 boolean: 20 date-time: 20 ------------------------------------------------- But, is there a 1-line way to sort and print? Thanks!