如何将碰撞的值插入结果表? 这就是我尝试过的事情:
for elements in collisions:
for i in results:
for j in i:
results[i][j] = elements
collisions = [26, 12, 16, 17, 12, 16, 14, 8, 4, 2, 8, 5, 3, 4, 5, 3, 2, 3, 2, 6, 2, 2, 2, 3, 0, 0, 0, 0]
result = [[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, 0, 0, 0]]
想要:
[[26, 12, 4, 3, 2, 2, 0], [12, 16, 2, 4, 3, 2, 0], [16, 14, 8, 5, 2, 2, 0], [17, 8, 5, 3, 6, 3, 0]]
提前致谢
答案 0 :(得分:0)
这是将列表分解为子列表的简单方法。
x=0
result = []
collisions = [26, 12, 16, 17, 12, 16, 14, 8, 4, 2, 8, 5, 3, 4, 5, 3, 2, 3, 2, 6, 2, 2, 2, 3, 0, 0, 0, 0]
while x < len(collisions)/7:
sub_list = []
for i in range(x,len(collisions),4):
sub_list.append(collisions[i])
result.append(sub_list)
x += 1
print collisions
print result
[26, 12, 16, 17, 12, 16, 14, 8, 4, 2, 8, 5, 3, 4, 5, 3, 2, 3, 2, 6, 2, 2, 2, 3, 0, 0, 0, 0]
[[26, 12, 4, 3, 2, 2, 0], [12, 16, 2, 4, 3, 2, 0], [16, 14, 8, 5, 2, 2, 0], [17, 8, 5, 3, 6, 3, 0]]
注意:没有错误检查