【Python】使用Counter方法统计字符串每个字符出现的次数

from collections import Counter


a = "a;lskdh!`foiegn``as;ldnf,asd.121,2ljladsfkja`sdijfhaosjlfd,gjsdfg.as.dl"
b = Counter(a)
print(b)
-------------------------------
Counter({'s': 8, 'd': 8, 'a': 7, 'l': 6, 
'f': 6, 'j': 5, '`': 4, 'g': 3, ',': 3, 
'.': 3, ';': 2, 'k': 2, 'h': 2, 'o': 2, 
'i': 2, 'n': 2, '1': 2, '2': 2, '!': 1, 
'e': 1})

 

你可能感兴趣的:(❤You,need,Python!,------【Python】,------【问题积累】)