It's our wits that make us men.

Python统计一个字符串中的每一个字符出现了多少次

Posted on By ZY
个人分类:Python

from collections import Counter
li = "j\xa0\xa0\xa0ddd\xa0cccc"
s = Counter(li)
print(s) # s是个字典 Counter({'\xa0': 4, 'c': 4, 'd': 3, 'j': 1})
print(s)['\xa0'] # 4