I would like to give some feedback about getting wrong result in test.
String "One" gives "e" as an answer in "try it" test, but "o" in "run" test.
From: http://www.checkio.org/mission/most-wanted-letter/solve/
HTTP_USER_AGENT:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
My Code:
alphabet=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
frequency=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
def checkio(text):
text=text.lower()
for char in text:
if char in alphabet:
frequency[alphabet.index(char)]+=1
maxfreq=max(frequency)
for elem in frequency:
if elem == maxfreq:
return alphabet[frequency.index(elem)]
break
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.")
Created at: 2014/07/03 11:56; Updated at: 2014/07/03 11:56