counter

Counter 集成于 dict 类,因此也可以使用字典的方法,此类返回一个以元素为 key 、元素个数为 value 的 Counter 对象集合

>>> from collections import Counter
>>> s = "hello pinsily"
>>> d = Counter(s)
>>> d
Counter({'l': 3, 'i': 2, 'h': 1, 'e': 1, 'o': 1, ' ': 1, 'p': 1, 'n': 1, 's': 1, 'y': 1})
原文地址:https://www.cnblogs.com/xxupup/p/10747315.html