Created
February 1, 2011 15:33
-
-
Save dustingetz/806021 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import defaultdict | |
| def sorter_second_desc(x,y): | |
| """for sorting list of pairs by the second element, descending. | |
| e.g. count""" | |
| return -1 * cmp(x[1], y[1]) | |
| def main(): | |
| sentence='the quick brown FOX JumpeD Over the lazy dog' | |
| charCount=defaultdict(int) #int factory default is 0 | |
| for ch in sentence.lower(): | |
| charCount[ch]+=1 | |
| items = charCount.items() | |
| items.sort(sorter_second_desc) | |
| print items |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment