统计一个字符串里面出现次数最多的字母
def findmax(str):
str_d = {}
for i in str:
if i not in str_d.keys():
str_d[i] = 0
else:
str_d[i] += 1
ma = max(str_d,key=str_d.get)
return ma
s = 'sdftefcxcdfgdgd'
print(findmax(s))
统计一个列表里面出现次数最多的字母和次数
def text(l):
dic1 = {}
for i in l :
dic1[i]=l.count(i)
return (max(zip(dic1.values(),dic1.keys()))