【发布时间】:2016-02-11 10:45:42
【问题描述】:
我创建了一个 python 函数,它应该采用一系列 3D 坐标并将它们放在一个列表中(在一个列表中)。
但是当我打印出coord_list 时,它似乎没有正确附加,例如当输入这些坐标时:
[1,2,3]
[2,3,4]
[3,4,5]
coord_list 的最终输出(忽略“q”)将是:[[3,4,5],[3,4,5],[3,4,5]]。
为什么它不能正确附加,如何解决?
def coords() :
xyz_list = []
coord_list = []
while 1 :
xyz = raw_input("Enter co-ordinates (x,y,z) enter 'q' when done: ")
xyz = str(xyz)
del xyz_list[:]
for num in xyz.split(","):
xyz_list.append(num)
print xyz_list
if xyz[0] != 'q' :
coord_list.append(xyz_list)
print coord_list
else :
break
coords()
【问题讨论】:
-
我测试了你的脚本,没问题。
-
您能否更具体地说明“为什么不能正确附加”的意思?你认为它应该做什么?
标签: python list function append coordinates