1. 程式人生 > >字符串計數

字符串計數

def pan default pri 字符串 int set 計數 text

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))

字符串計數