当前位置: 代码迷 >> 综合 >> letter count
  详细解决方案

letter count

热度:54   发布时间:2024-01-30 16:00:26.0

题目

找出字母出现最多的字母

思路

用hash表

代码

def lettercount(s):freq = {}for p in s:word = ''.join(c for c in p if c.isalpha())if word:freq[word] = 1 + freq.get(word,0)max_word = ''max_count = 0for key,value in freq.items():if value>max_count:max_count = valuemax_word = keyprint(max_word)print(max_count)
  相关解决方案