<分区> 分区>
我是 Python 的新手,出于某些需要,我想弄清楚如何使用列表列表的列表。
这是我在做什么:
segment_coef = [[list()]*4]*17
print segment_coef
segment_coef[0][0].append(1)
segment_coef[1][0].append(2)
segment_coef[2][0].append(3)
print segment_coef
在第一次 print 之后我有:
[ [ [],[],[],[] ] , ... 14 more time ... , [ [],[],[],[] ] ]
在这三个 append 命令之后,我想要像这样:
[ [ [1],[],[],[] ] , [ [2],[],[],[] ], [ [3],[],[],[] ] ]
但是我有:
[ [ [1,2,3],[1,2,3],[1,2,3],[1,2,3] ] , [ [1,2,3],[1,2,3],[1,2,3],[1,2,3] ], ... up to the end ]
我做错了什么?
