Sorting a list
DFS
nospam at dfs.com
Sun Apr 3 14:30:00 EDT 2016
More information about the Python-list mailing list
Sun Apr 3 14:30:00 EDT 2016
- Previous message (by thread): i cant seem to figure out the error
- Next message (by thread): Sorting a list
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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!
- Previous message (by thread): i cant seem to figure out the error
- Next message (by thread): Sorting a list
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list