Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106387
| From | DFS <nospam@dfs.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Sorting a list |
| Date | 2016-04-03 14:30 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <ndrn97$bco$1@dont-email.me> (permalink) |
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!
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll 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