快速统计字符出现次数

 

快速的统计出字符出现的次数,并以字典显示出来

import pprint

msg = 'It was a bright cold day in April, and the clocks were strikingthirteen'
count = dict()

for i in msg:
    count.setdefault(i, 0)
    count[i] = count[i] + 1

pprint.pprint(count)

 

posted @ 2021-04-18 16:42  十一的杂文录  阅读(172)  评论(0编辑  收藏  举报