1042. 字符統計(20)
請編寫程序,找出一段給定文字中出現最頻繁的那個英文字母。
輸入格式:
輸入在一行中給出一個長度不超過1000的字符串。字符串由ASCII碼錶中任意可見字符及空格組成,至少包含1個英文字母,以回車結束(回車不算在內)。
輸出格式:
在一行中輸出出現頻率最高的那個英文字母及其出現次數,其間以空格分隔。如果有並列,則輸出按字母序最小的那個字母。統計時不區分大小寫,輸出小寫字母。
輸入樣例:This is a simple TEST. There ARE numbers and other symbols 1&2&3...........輸出樣例:
e 7
from collections import Counter
import re
if __name__ == '__main__':
counter = Counter(raw_input().lower())
counter = {key:counter[key] for key in counter if re.match(r'[a-z]', key)}
counter = sorted(counter.iteritems(), key = lambda data:data[1], reverse = True)
print counter[0][0], counter[0][1]