『Collections』Counter计数

Counter()方法

计数器,返回字典,会同时去重,文本处理常用

from collections import Counter
co = Counter(list('abcdefgad'))
co
Out[7]: 
Counter({'a': 2, 'b': 1, 'c': 1, 'd': 2, 'e': 1, 'f': 1, 'g': 1})

  

原文地址:https://www.cnblogs.com/hellcat/p/7710430.html