给定一个字符串,计算每个字母出现的次数(字典方法解决)

def histogram1(s):
    d = dict()
    for c in s:
        d[c] = d.get(c,0)+1
    return d
h = histogram1('adwagagg')
print(h)

 

posted @ 2022-03-23 21:22  玫瑰少年  阅读(301)  评论(0编辑  收藏  举报