python123字典统计排序1源代码,按值对字典字典进行排序Python(3级字典)

I have a dict like this:

{

'INT-ABC1':

{

'acc1': {'val': -22313.7381693064, 'Qua': -241.0},

'acc2': {'val': -1312.940854148, 'Qua': -13.0}

},

'INT-ABC2':

{

'acc1': {'val': -131.2510359399, 'Qua' : -23.0},

'acc3': {'val': -131.40521409002, 'Qua' : -13.0},

'acc5': {'val': -12312.7688190937, 'Qua' : -1313.0}

}

}

I need to sort it by 'val' and get a similar dict out of it.

解决方案

Something like this would work, but I think If you are starting with python, you should learn about the sorted function in python.

>>> sorted(k.items(), key = lambda x: x[1][0].itervalues().next()['val'])

Where k is your dictionary.

Link provided by viki.omega9 in his answer should be a good starting point.

Note: The command will return a list of tuples (or pairs) in sorted order of the form:

[(key1, val1), (key2, val2)]

because dictionaries by nature are unordered.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值