一、collections系列:

collections其实是python的标准库,也就是python的一个内置模块,因此使用之前导入一下collections模块即可,collections在python原有的数据类型str(字符串), int(数值), list(列表) tuple(元组), dict(字典)的基础之上增加一些其他的数据类型即方法,具体如下:

1、Counter(dict):计数器,扩展的字典的方法,对指定数据的字串做统计出现的次数,结果是一个元组,如:

pathon 基础学习-集合(set),单双队列,深浅copy,内置函数
1 import  collections
2 li = ("asdasdsdasdahjlklknlknfd")
3 a = collections.Counter(li)
4 print(a)
5 
6 执行结果:
7 Counter({'d': 5, 's': 4, 'a': 4, 'k': 3, 'l': 3, 'n': 2, 'j': 1, 'h': 1, 'f': 1})
pathon 基础学习-集合(set),单双队列,深浅copy,内置函数

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2021-10-20
  • 2021-12-24
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-06
  • 2022-12-23
  • 2021-05-29
  • 2021-10-16
  • 2021-06-03
  • 2021-10-01
  • 2022-01-14
相关资源
相似解决方案