Created
December 12, 2013 07:01
-
-
Save yunlzheng/7924156 to your computer and use it in GitHub Desktop.
check_io most_wanted_letter
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
| # coding: utf-8 | |
| import string | |
| def checkio(text): | |
| return sorted( | |
| dict( | |
| [(w, text.count(w)) for w in "-".join(text.encode('utf-8').translate( | |
| None, string.punctuation | |
| ).translate( | |
| None, string.whitespace | |
| ).lower()).split('-')] | |
| ).iteritems(), key=lambda d: d[1], reverse=True)[0][0] | |
| #These "asserts" using only for self-checking and not necessary for auto-testing | |
| if __name__ == '__main__': | |
| assert checkio("Hello World!") == "l", "Hello test" | |
| assert checkio("How do you do?") == "o", "O is most wanted" | |
| assert checkio("One") == "e", "All letter only once." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment