当前位置: 首页 > news >正文

以下不是网站开发语言的哪项工信部域名备案管理系统

以下不是网站开发语言的哪项,工信部域名备案管理系统,国外域名注册平台,游戏网页计数器counter是包含在collections模块中的容器。 什么是容器Container#xff1f; 容器是容纳对象的对象。它们提供了一种访问所包含对象并对其进行迭代的方法。内置容器的例子有元组、列表和字典。其他内容包含在“collections”模块中。 Counter是dict的子类。因此#…计数器counter是包含在collections模块中的容器。 什么是容器Container 容器是容纳对象的对象。它们提供了一种访问所包含对象并对其进行迭代的方法。内置容器的例子有元组、列表和字典。其他内容包含在“collections”模块中。 Counter是dict的子类。因此它是一个无序的集合其中元素和它们各自的计数被存储为字典。这相当于一个包或多个其他语言集。 语法 class collections.Counter([iterable-or-mapping])初始化 计数器的构造函数可以通过以下任一方式调用 包含一系列项目使用包含键和计数的字典带有将字符串名称映射到计数的关键字参数 初始化计数器 # A Python program to show different ways to create # Counter from collections import Counter# With sequence of items print(Counter([B,B,A,B,C,A,B,B,A,C]))# with dictionary print(Counter({A:3, B:5, C:2}))# with keyword arguments print(Counter(A3, B5, C2))输出 Counter({B: 5, A: 3, C: 2}) Counter({B: 5, A: 3, C: 2}) Counter({B: 5, A: 3, C: 2})计数器更新 我们也可以通过以下方式创建一个空计数器 coun collections.Counter()并且可以通过update() 方法进行更新。相同的语法 coun.update(Data)# A Python program to demonstrate update() from collections import Counter coun Counter()coun.update([1, 2, 3, 1, 2, 1, 1, 2]) print(coun)coun.update([1, 2, 4]) print(coun)输出 Counter({1: 4, 2: 3, 3: 1}) Counter({1: 5, 2: 4, 3: 1, 4: 1}数据可以用初始化中提到的三种方式中的任何一种提供计数器的数据将增加而不是替换。计数也可以为零或负数。 # Python program to demonstrate that counts in # Counter can be 0 and negative from collections import Counterc1 Counter(A4, B3, C10) c2 Counter(A10, B3, C4)c1.subtract(c2) print(c1)输出 Counter({c: 6, B: 0, A: -6})列表中的唯一计数 我们可以使用Counter来计算列表或其他集合中的不同元素。 # An example program where different list items are # counted using counter from collections import Counter# Create a list z [blue, red, blue, yellow, blue, red]# Count distinct elements and print Counter aobject print(Counter(z))输出 Counter({blue: 3, red: 2, yellow: 1})打印计数器值 我们还可以使用keys() 、values() 和items() 方法访问计数器的所有键和值。这些方法分别返回计数器中的键、值和键值对的视图。 from collections import Counter my_counter Counter(abracadabra) print(my_counter.keys()) print(my_counter.values()) print(my_counter.items())输出 dict_keys([a, b, r, c, d]) dict_values([5, 2, 2, 1, 1]) dict_items([(a, 5), (b, 2), (r, 2), (c, 1), (d, 1)])访问计数器 一旦初始化计数器就像字典一样被访问。此外它不会引发KeyValue错误如果key不存在而是值的计数显示为0。 # Python program to demonstrate accessing of # Counter elements from collections import Counter# Create a list z [blue, red, blue, yellow, blue, red] col_count Counter(z) print(col_count)col [blue,red,yellow,green]# Here green is not in col_count # so count of green will be zero for color in col:print (color, col_count[color]) 输出 Counter({blue: 3, red: 2, yellow: 1}) blue 3 red 2 yellow 1 green 0elements() elements() 方法返回一个迭代器该迭代器生成Counter已知的所有项。 注意不包括count 0的元素。 # Python example to demonstrate elements() on # Counter (gives back list) from collections import Countercoun Counter(a1, b2, c3) print(coun)print(list(coun.elements()))输出 Counter({c: 3, b: 2, a: 1}) [a, b, b, c, c, c]most_common() most_common() 用于产生N个最频繁遇到的输入值及其相应计数的序列。 # Python example to demonstrate most_elements() on # Counter from collections import Countercoun Counter(a1, b2, c3, d120, e1, f219)# This prints 3 most frequent characters for letter, count in coun.most_common(3):print(%s: %d % (letter, count)) 输出 f: 219 d: 120 c: 3
http://www.zqtcl.cn/news/768605/

相关文章:

  • 优化网站搭建创业项目网站建设规划
  • 温岭网站开发网站建设程序文件
  • 有什么网站可以做深圳初二的试卷练习商城网站功能
  • 网站托管就业新闻今天的最新新闻
  • 重庆网站建设方案书国外做电商平台的网站有什么
  • 微信扫一扫登录网站如何做网络平台怎么弄
  • 怎么做网页模板展示网站株洲网红餐厅
  • 优秀学校网站设计正规抖音代运营公司排名
  • 网站的网站建设公司太原中小企业网站制作
  • 北京网站建设搜q.479185700模特公司网站模板
  • 网站设置什么意思wordpress 专题页面
  • 网站推广要具备什么购物网站多少钱
  • 重庆免费做网站在线做ppt
  • wordpress固定链接设置404阳江seo优化
  • 响应网站模板下载wordpress恢复网站
  • 公司网站建设的定位语要怎么取网站开发中常见的注册界面
  • 免费企业查询网站wordpress侧边栏加载过慢
  • 网站写好了怎么做后台管理链接是什么意思
  • 低价格制作网站wordpress 注册用户
  • 免费发布租房信息网站wordpress页面回收站
  • 长网页网站信息技术教案 建设我们的网站
  • 免费网站建设可信吗wordpress divi布局
  • 网站百度不收录wordpress偽靜態
  • 沈阳php网站建网站需要学什么
  • WordPress多站点绑定域名百度帐号注册
  • 网站营销队伍网站建设明薇通网络
  • 做网站的公司重庆万网x5 wordpress
  • 印刷设计营销网站网站设置成黑白
  • 百度自助建站官网上海徐汇网站建设
  • 网站定制 北京贵阳网站建设公司哪家好