Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
# 列表推导式
# 5*5二维列表
b = [[0 for i in range(5)] for x in range(5)]
# for循环 避免浅拷贝
# 5*5二维列表
a = []
for i in range(5):
a.append([])
for j in range(5):
a[i].append(0)
Out:
[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]