【发布时间】:2014-11-11 18:31:39
【问题描述】:
我想将临时列表的值添加到主列表中。我尝试将一些值添加到临时列表中,然后将临时列表附加到主列表中,如下所示,但它始终显示主列表中的最新值。
>>> temp =[]
>>> temp.append(123)
>>> temp.append(10)
>>> temp.append(18)
>>> mutR =[]
>>> mutR.append(temp)
>>> print mutR
[[123, 10, 18]]
>>> temp[:]=[]
>>> temp.append(3)
>>> temp.append(4)
>>> temp.append(5)
>>> mutR.append(temp)
>>> print mutR
[[3, 4, 5], [3, 4, 5]]
我的期望是:
>>> print mutR
[[123, 10, 18], [3, 4, 5]]
但它是[[3, 4, 5], [3, 4, 5]]。
【问题讨论】: