Skip to content

Instantly share code, notes, and snippets.

@sumoward
Created July 15, 2014 15:31
Show Gist options
  • Save sumoward/7adc91c13539de48c757 to your computer and use it in GitHub Desktop.
Save sumoward/7adc91c13539de48c757 to your computer and use it in GitHub Desktop.
def checkio(text):
text = text.lower()
check_list = sorted(set(text))
store_no = 0
store_letter = ''
for letter in check_list:
if letter.isalpha():
ans = text.count(letter)
if ans > store_no :
store_letter = letter
store_no = ans
print(store_letter)
return store_letter
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
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."
assert checkio("Oops!") == "o", "Don't forget about lower case."
assert checkio("AAaooo!!!!") == "a", "Only letters."
assert checkio("abe") == "a", "The First."
print("Start the long test")
assert checkio("a" * 9000 + "b" * 1000) == "a", "Long."
print("The local tests are done.")
@sumoward
Copy link
Author

import string

def checkio(text):
"""
We iterate through latyn alphabet and count each letter in the text.
Then 'max' selects the most frequent letter.
For the case when we have several equal letter,
'max' selects the first from they.
"""
text = text.lower()
return max(string.ascii_lowercase, key=text.count)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment