【字典】2852. 统计字母频率

aspen138 edited 3 年前

s=input()
cnt=0
d=dict()
for i in s:
    if i.isalpha():
        cnt+=1
        if i not in d:
            d[i]=1
        else:
            d[i]+=1
d=sorted(d.items(),key=lambda x:x[0],reverse=False)
d=sorted(d,key=lambda x:x[1],reverse=True)
ch=d[0][0]
freq=d[0][1]/cnt
print('{} {:.2f}'.format(ch,freq))

Comments