qq_39254668
2021-08-06 17:20
采纳率: 100%
浏览 82

python,如何给二维数组编号?


a = [[0] * 4] * 4
id = 0
for i in range(4):
    for j in range(4):
        a[i][j] = copy.deepcopy(id)
        id += 1
print(a)

实际输出:
[[12, 13, 14, 15], [12, 13, 14, 15], [12, 13, 14, 15], [12, 13, 14, 15]]
我希望的输出:
[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]

2条回答 默认 最新

相关推荐 更多相似问题