33问答网
所有问题
python collections counter的值怎么取出来
如题所述
举报该问题
推荐答案 2017-08-23
使用counter类的items()函数即可,Python3程序如下:
for each in count.items():#假设存在counter类的count
(a,b)=each
print(a,b.sep='\t',end='\n',file='./test.txt')
温馨提示:答案为网友推荐,仅供参考
当前网址:
http://33.wendadaohang.com/zd/dPPW4Pc40Bd5PPB5ch.html
其他回答
第1个回答 2017-03-09
最为简单的方法是利用表理解,生成一个新的字典必须要保证键值是一一对应的d={'one':1,'two':2,'three':3,'four':4}di={v:kfork,vind.items()}di[1]
第2个回答 2019-02-26
这还不简单、、、通过键来访问值啊。。
s1 = ['zh','like','like','di','ag']
c2 = Counter(s1)
print(c2)
print(c2['zh'])
相似回答
python如何
统计字符串中0-9出现的次数?
答:
可以使用
collections
模块中的
Counter
类来统计输入的数字中0-9出现的次数。示例代码:在这段代码中,输入的数字字符串会被传入Counter类的构造函数中,然后通过counts[str(i)]来获取i出现的次数。最后通过循环打印出来。break代码解释:第一行让用户输入一个整数n,并将其转换为整型。第二行输出提示信息。...
如何
用
PYTHON
做分词处理
答:
首先pip安装一下jieba,这个可以分词 然后用计数器
Counter
()统计一下得到的分词中各词的数量 最后most_common(5),是打印出排名前五位的词(包括特殊符号)encoding:utf-8import sysreload(sys)sys.setdefaultencoding('utf-8') import jiebafrom
collections
import Counter str1 = open('tips.txt...
用
python
找出某一序列中的第一个非重复数字
答:
可以利用collections库的Counter方法,
先计数并生成一个count_lst的字典,然后遍历一次lst, count_lst值==1的第一个数输出,跳出循环即可
from collections import Counterlst = [2,2,4,1,5,7]count_lst = Counter(lst)for i in lst:if count_lst.has_key(i) and count_lst[i]==1:print i...
大家正在搜
python counter函数
Python counter
python中counter用法
python里的count
python setattr
python repeat
python randrange
python extend
python object
相关问题
python counter计数后怎么从大到小返回值
怎么调用python中的collections
如何用python统计一个txt文件中某个单词出现的次数
用Python怎么统计一个列表的元素种类和各个种类的个数?
python列表中重复元数的个数以及怎么提取2个重复元数之间...
python的counter函数怎么用
python3 collections.counter没有
怎么在python 的一个数列中挑选出出现次数最多的数,并打...