Python collections.Counter(s)

Python collections.Counter(s)

统计字符串s中各个字符的个数

s = "loveleetcode"
# build hash map : character and how often it appears
count = collections.Counter(s)

结果:
Python collections.Counter(s)_第1张图片

你可能感兴趣的:(Python)