-3
一個列表中的更改如何反映在另一個列表中?Python中的列表引用
lst = [0, 0]
sublist = [lst[0], lst[0], lst[1], lst[1]]
print sublist
>> [0, 0, 0, 0]
lst[0] = 1
print sublist
>> [0, 0, 0, 0]
# But I would like to
>> [1, 1, 0, 0]
我如何得到想要的結果? 對不起,我的英文。
列表不支持。您需要找到其他方法來解決您希望通過這樣做解決的任何問題。 – user2357112
相關:https://nedbatchelder.com/text/names.html – chepner
如果您想要傳播效果,請確保該對象是可變的,在您的示例中,您需要使'lst'的元素變爲可變。 – nos