cellection是作为字典、元组(列表与元组可互相转换)的扩充,在此需要导入cellection

一、计数器(counter)

  counter是对字典类型的补充,用户获取字典中元素出现的次数。它具备字典所有的功能以及自己自带的功能。

  

  
1 import collections
2 stra = collections.Counter('asdfasdfasdfdgghjertgfgsa')
3 print(stra)
4 输出的结果是:
5 Counter({'a': 4, 'd': 4, 'g': 4, 'f': 4, 's': 4, 'e': 1, 'h': 1, 'j': 1, 'r': 1, 't': 1})
6 后面的数字表示的是出现的次数。
Counte

相关文章:

  • 2021-12-05
  • 2021-12-05
  • 2021-05-02
  • 2021-08-08
  • 2021-05-25
  • 2021-11-17
  • 2022-12-23
猜你喜欢
  • 2021-06-23
  • 2021-05-03
  • 2021-10-30
  • 2021-11-27
  • 2022-12-23
  • 2021-12-05
  • 2021-12-06
相关资源
相似解决方案