• Why so bad?

Question related to mission The Most Wanted Letter


Why so bad?

When there was input "One" result had to be "e". Now there is input "AAaooo!!!!" it has to be "a" ?!?! Sory but it's driving me crazy.

From: http://www.checkio.org/mission/most-wanted-letter/solve/


Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:31.0) Gecko/20100101 Firefox/31.0

My Code:

def checkio(text):
    text = text.lower()
    brojilo = 0
    for i in text:
        x = text.count(i)
        print x
        if brojilo < x and i != '!':
            brojilo = x
            e = i
        elif x == brojilo:
            e = i
    return e

if __name__ == '__main__':
    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert checkio(u"Hello World!") == "l", "Hello test"
    assert checkio(u"How do you do?") == "o", "O is most wanted"
    assert checkio(u"One") == "e", "All letter only once."
    assert checkio(u"Oops!") == "o", "Don't forget about lower case."
    assert checkio(u"AAaooo!!!!") == "a", "Only letters."
    assert checkio(u"abe") == "a", "The First."
    print("Start the long test")
    assert checkio(u"a" * 9000 + u"b" * 1000) == "a", "Long."
    print("The local tests are done.")