Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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
Python 3.x python中排序加权无向图_Python 3.x_Data Structures_Undirected Graph - Fatal编程技术网

Python 3.x python中排序加权无向图

Python 3.x python中排序加权无向图,python-3.x,data-structures,undirected-graph,Python 3.x,Data Structures,Undirected Graph,我需要根据权重在下面的图表中排序 graph_G = {'A': [('B', 7), ('E', 2)], 'B': [('C', 6)], 'C': [('A', 5), ('D', 3)], 'D': [('E', 1)], 'E': [('A', 7)], } 我试过了 print(“排序Dict%s”%(已排序(graph_G.items(),key=itemgetter(1))) 这是根据元组的第一个字符对

我需要根据权重在下面的图表中排序

    graph_G = {'A': [('B', 7), ('E', 2)],
       'B': [('C', 6)],
       'C': [('A', 5), ('D', 3)],
       'D': [('E', 1)],
       'E': [('A', 7)],
      }
我试过了
print(“排序Dict%s”%(已排序(graph_G.items(),key=itemgetter(1)))

这是根据元组的第一个字符对字典进行排序。我想在元组的第二部分(权重)对其进行排序

所以我想把它分类如下

graph_G = {'A': [('E', 2), ('B', 7)],
       'B': [('C', 6)],
       'C': [('D', 3), ('A', 5)],
       'D': [('E', 1)],
       'E': [('A', 7)],
      }

有什么方法可以做到这一点吗?

检查此链接:也检查此链接:在本例中,您的预期输出是什么?