我有一个字典列表,其中包含一个列表作为其值。我想根据列表的值对这个字典列表进行排序。这是数据的样子:
[{'len': [[1.0, 0.15167129908211108],
[0.15167129908211108, 0.9999999999999999]]},
{'count': [[1.0, -0.0062137259524966066],
[-0.006213725952496607, 0.9999999999999999]]},
{'dom_length': [[0.9999999999999999, 0.14866302421674646],
[0.14866302421674643, 0.9999999999999999]]},
{'p_length': [[1.0, 0.06551622215539057],
[0.06551622215539057, 0.9999999999999999]]},
{'date_length': [[1.0, 0.18233544694774714],
[0.18233544694774714, 0.9999999999999999]]},
{'file_length': [[0.9999999999999998, 0.08244043289497642],
[0.08244043289497642, 0.9999999999999999]]}]
我想对这些数据进行排序以返回前 3 个字典。这是所需的输出:
[{'date_length': [[1.0, 0.18233544694774714],
[0.18233544694774714, 0.9999999999999999]]},
{'len': [[1.0, 0.15167129908211108],
[0.15167129908211108, 0.9999999999999999]]},
{'dom_length': [[0.9999999999999999, 0.14866302421674646],
[0.14866302421674643, 0.9999999999999999]]}]
答案 0 :(得分:1)
您可以按子列表的sum
的{{1}}进行排序,然后得到顶部的sum
(假设字典中只有一对3
,否则您需要另一个外部 key-value
或其他条件):
sum