題目:輸出給定字符串中出現次數最多 的字符(不論大小寫),字符串中可能存在大小寫,當存在出現次數同樣的字符,此時按照字符在字母表中的順序輸出位於字母表前面的字符。this
import string def checkio(text): alpha=['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'] #replace this for solution #最簡潔的解決代碼爲一下注釋的三行便可 #text=text.lower() #alpha=string.ascii_lowercase #return max(alpha,key=text.count) max_str=[0,0] for i in range(26): if text.lower().count(alpha[i]) > max_str[1] : max_str[0]=alpha[i] max_str[1]=text.lower().count(alpha[i]) return max_str[0] 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.")