Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python2.7中,将嵌套的dict排序到有序列表中_Python_Python 2.7_Sorting_Dictionary - Fatal编程技术网

在Python2.7中,将嵌套的dict排序到有序列表中

在Python2.7中,将嵌套的dict排序到有序列表中,python,python-2.7,sorting,dictionary,Python,Python 2.7,Sorting,Dictionary,我有以下意见: d = {'d_1': {'score': 5.2, 'concept': 'a'}, 'd_2': {'score': 10.1, 'concept': 'e'}, 'd_3': {'score': 1.5, 'concept': 'c'}, 'd_4': {'score': 20.2, 'concept': 'd'}, 'd_5': {'score': 0.9, 'concept': 'b'}} 我想得到一个按分数排序的列表,

我有以下意见:

d = {'d_1': {'score': 5.2, 'concept': 'a'}, 
     'd_2': {'score': 10.1, 'concept': 'e'}, 
     'd_3': {'score': 1.5, 'concept': 'c'}, 
     'd_4': {'score': 20.2, 'concept': 'd'}, 
     'd_5': {'score': 0.9, 'concept': 'b'}}
我想得到一个按分数排序的列表,如下所示:

d_sorted = [{'d_4': {'score': 20.2, 'concept': 'd'}},
            {'d_2': {'score': 10.1, 'concept': 'e'}},
            {'d_1': {'score': 5.2, 'concept': 'a'}},
            {'d_3': {'score': 1.5, 'concept': 'c'}},
            {'d_5': {'score': 0.9, 'concept': 'b'}}]
我尝试了以下方法,但这将按概念排序,而不是评分:

d_sorted = sorted(d.items(), key=operator.itemgetter(1), reverse=True)
在Python2.7中,如何按分数键(降序)将这个嵌套的dict排序到一个有序列表中


编辑:这不是的副本,因为它涉及嵌套的dict。

首先提取值:

[{k: v} for k, v in sorted(d.items(), key=(lambda x: x[1]['score']), reverse=True)]

我知道,我想从我的口述中得到一个已排序的列表。可能的副本