我正在尝试写一个简单的小程序来计算一组给定数字的均值、中位数、模式和标准差,但我在编写模式部分的脚本时遇到了麻烦,有什么帮助吗?我使用的是python 3.3.2
发布于 2014-03-21 06:07:04
尝试计数器模块:
import collections
c = collections.Counter('extremely')
cOut4:计数器({‘e’:3,'m':1,'l':1,'r':1,'t':1,'y':1,'x':1})
c.items()Out7:('e',3),('m',1),('l',1),('r',1),('t',1),('y',1),('x',1)
srted = sorted(c.items(), key= lambda (k,v): -v)
srtedOut9:('e',3),('m',1),('l',1),('r',1),('t',1),('y',1),('x',1)
top = srted[0]
topOut11:('e',3)
k,v = top
kOut13:'e‘
vOut14: 3
https://stackoverflow.com/questions/22545792
复制相似问题