Python 列表嵌套字典的数据排序
1、相关代码
针对data[‘data’][‘list’]部分进行排序
def test():
data = {
"message": "OK", "code": "0", "data": {
"totalRecords": 7, "device": "influxdb", "list": [
{
"ip": "10.32.7.186", "_in_use": 25.005804979490698, "time": 1630026435000},
{
"ip": "10.32.7.185", "_in_use": 34.495937326525734, "time": 1630026134000},
{
"ip": "10.32.7.184", "_in_use": 39.8273490674876, "time": 1630025714000},
{
"ip": "10.32.7.183", "_in_use": 24.988928103126, "time": 1630026494000},
{
"ip": "10.32.7.182", "_in_use": 17.92136649408284, "time": 1630023014000},
{
"ip": "10.32.7.181", "_in_use": 28.82683374611834, "time": 1630026134000},
{
"ip": "10.32.7.180", "_in_use": 63.368333765813446, "time": 1630024874000}], "timetaken": 0.00940847396850586},
"result": 'true', "request_id": "44ee92d976ef4a8c990baad193ac3aaf"}
res = data['data']['list']
RES=sorted(res, key=lambda tmp: tmp['_in_use'],reverse=True)
for i in RES:
print(i)
if __name__ == '__main__':
test()
2、执行结果:
今天的文章Python 列表嵌套字典的数据排序分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/10236.html