【Python中的collections】collections.Counter()

  • Python中的collections.Counter(iterable)是一个计数器,实现了各元素的数量统计,以键值对的形式存储
  • iterable是一个迭代器,例如list,字符串等
collections.Counter("aabbccc")
''
返回结果为:
Counter({
    
    'c': 3, 'b': 2, 'a': 2})
''

猜你喜欢

转载自blog.csdn.net/m0_48086806/article/details/132228537