问题是如何通过基于max和low value的键提取值来解析字典。然后比较其中的值,并根据计算添加一些关键值。也许问题很复杂,但我会用代码提供更多的解释。在
[
{
"YCI": 0.014076729909151329,
"TCI": 0.5610661498232027,
"FCI": 0.327632092582722,
"TFCI": 3.04906430661623,
"naziv": "HDZ",
"YCSI": 14.49723089452966
},
{
"YCI": 0.04249999676677044,
"TCI": 0.33129318126147167,
"FCI": 1.677073944380761,
"TFCI": 4.326953034001479,
"naziv": "HNS",
"YCSI": 56.80909574468085
},
{
"YCI": 0,
"TCI": 0.40603351151808614,
"FCI": 0,
"TFCI": 12.61045547126369,
"naziv": "HSP AS",
"YCSI": 0
},
{
"YCI": 2.231205214448367,
"TCI": 0,
"FCI": 0,
"TFCI": 0,
"naziv": "HSS",
"YCSI": 949.343111111111
}
]
好的,这是我的字典。现在如何比较字典中的键:
以他们的价值观为基础。如果值YCI的值最大,那么它应该在新字典中设置数字1,并且该逻辑也应用于字典中的其他键。 输出如下:
最大值得到数字1,最小值取决于dictionary包含多少对象。在
print max(nvalues[0].iteritems(), key=operator.itemgetter(1))[1]
有了这段代码,我可以提取最高值,但是如何在字典的值内对其进行排序。如果你能给我一些逻辑来解决这个问题,我将不胜感激。在
相关问题 更多 >
编程相关推荐