使用对另一个列表的引用的Python列表构造函数

使用对另一个列表的引用的Python列表构造函数,python,list,constructor,reference,Python,List,Constructor,Reference,我将节点[0][2]指定为节点[1],后来又修改了节点[1],但节点[0][2]仍在打印输出中[]。如何在构造节点[0]时传递节点[1]的引用 node=[[] for i in range(5)] node[0]=['d', 'Test Market', node[1], "Don't test market", node[2]] node[1]=['e', 'Local success', 0.6, node[3], 'Local Failure', 0.4, node[4]] node[2

我将节点[0][2]指定为节点[1],后来又修改了节点[1],但节点[0][2]仍在打印输出中[]。如何在构造节点[0]时传递节点[1]的引用

node=[[] for i in range(5)]
node[0]=['d', 'Test Market', node[1], "Don't test market", node[2]]
node[1]=['e', 'Local success', 0.6, node[3], 'Local Failure', 0.4, node[4]]
node[2]=['t', 23]
node[3]=['t', 45]
node[4]=['t', 12]
print node

[['d', 'Test Market', [], "Don't test market", []], ['e', 'Local success', 0.6, [], 'Local Failure', 0.4, []], ['t', 23], ['t', 45], ['t', 12]]
````试试看

node[2][:] = ['t',23]
原因是

node[2] = [1,2,...]
覆盖节点[2]上的值

鉴于

node[2][:] = [1,2,...]
填充节点[2]处的现有阵列(过度简化,但meh)


这可能有助于您可视化流程

您是否尝试更改作业顺序。节点[0]之前的节点[1]。对于我的应用程序,按顺序记录节点是很自然的。乔兰的回答很有效,也很有解释力!