字符串计数

import pprint
text = "aaaa bbbb ccc dd ee ff gg h i j kkkk"

count = {}

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

# pprint.pprint(count)
print(pprint.pformat(count))

 

posted on 2017-09-03 15:51  winecork  阅读(96)  评论(0编辑  收藏  举报

导航