我需要一个坐标列表,以扩大两个新的坐标后,每个原始坐标,以保持一个“绘图”秩序。你知道吗
我已经阅读并理解了一个简单的循环将运行到一个无限循环中,这就是为什么我在第一个列表上使用enumerate并在第二个列表上插入/附加。你知道吗
注意:循环中的“lc”和“rc”用于测试和显示这一点!你知道吗
coords=([100,100,10], [100,101,10], [100,102,10])
print (coords)
coords_n=[]
for idx,val in enumerate(coords):
print (idx,val)
coords_n.insert(idx, [val[0], val[1], val[2]])
lc= [val[0]-50, val[1], val[2]+40, 'lc']
coords_n.insert(idx+1,lc)
rc= [val[0]+50, val[1], val[2]+40, 'rc']
coords_n.insert(idx+2,rc)
print (coords_n)
结果是一个列表,但顺序不对,新元素位于列表末尾。你知道吗
new List:
0 [100, 100, 10]
1 [100, 101, 10]
2 [100, 102, 10]
3 [50, 102, 50, 'lc']
4 [150, 102, 50, 'rc']
5 [50, 101, 50, 'lc']
6 [150, 101, 50, 'rc']
7 [50, 100, 50, 'lc']
8 [150, 100, 50, 'rc']
因此,3+4应该位于位置1+2,然后是1和5+6,依此类推。你知道吗
使用
list.append
函数而不是摆弄insert和position我想你只是想用
append
而不是insert
试试这个:
相关问题 更多 >
编程相关推荐