我很难理解如何在python中创建变量列表(我是一个R程序员)。
我想创建一个变量列表名称来存储网络中的最小路径数组,例如6个负载(接收器)和3个发生器(源)使用'networkx',如下所示:
nx
是网络,G
是Digraph
for i in sinks:
print("Analysis for node ",i," :")
for j in sources:
for path in nx.all_simple_paths(G,j,i):
print (path)
"node_"+str(i)[i] = path #How to do this??
以这样的方式,“node_1”具有从节点1到所有源的所有路径,“node_2”从节点2到所有源的所有路径等。
答案 0 :(得分:2)
使用字典:
for i in sinks:
print("Analysis for node ",i," :")
for j in sources:
for path in nx.all_simple_paths(G,j,i):
print (path)
node[i][j] = path