Skip to content

Instantly share code, notes, and snippets.

@yunlzheng
Created December 12, 2013 07:01
Show Gist options
  • Select an option

  • Save yunlzheng/7924156 to your computer and use it in GitHub Desktop.

Select an option

Save yunlzheng/7924156 to your computer and use it in GitHub Desktop.
check_io most_wanted_letter
# 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