我有一个如下所示的数组列表:
c = [
[
[
[670515.231, 6577538.931, 51.703],
[670486.853, 6577531.536, 51.703],
[670488.927, 6577523.577, 51.703],
[670517.305, 6577530.971, 51.703],
[670515.231, 6577538.931, 51.703]
]
]
]
我想将它转换/格式化为数组的元组:s:
new_c =(
[670515.231, 6577538.931, 51.703],
[670486.853, 6577531.536, 51.703],
[670488.927, 6577523.577, 51.703],
[670517.305, 6577530.971, 51.703],
[670515.231, 6577538.931, 51.703])
最好的方法是什么?
答案 0 :(得分:2)
>>> c = [
... [
... [
... [670515.231, 6577538.931, 51.703],
... [670486.853, 6577531.536, 51.703],
... [670488.927, 6577523.577, 51.703],
... [670517.305, 6577530.971, 51.703],
... [670515.231, 6577538.931, 51.703]
... ]
... ]
... ]
>>> new_c = tuple(c[0][0])
>>> pprint(new_c)
([670515.231, 6577538.931, 51.703],
[670486.853, 6577531.536, 51.703],
[670488.927, 6577523.577, 51.703],
[670517.305, 6577530.971, 51.703],
[670515.231, 6577538.931, 51.703])
答案 1 :(得分:1)
你可以这样做:
c_tuple = tuple(c[0][0])
或者,如果列表的嵌套深度对于每种情况都不同:
tmp = c
while len(tmp) == 1:
tmp = tmp[0]
c_tuple = tuple(tmp)