一维数组转化为二维数组(将列表转为4*3)
records = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
result = []
for y in range(0, 4):
for x in range(0, 3):
if x == 0:
result.append([])
result[y].append(records[x + y * 2])
print(result)
运行结果:
[[1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9]]