我有一個(gè)坐標(biāo)列表如下:temp = [((20.0, 15.076858380630263), (20.0, 16.92468707613784)), (5.430012747754155, 3.3503228946034667), (7.364023506893538, 7.013767290971433), (11.932318028181742, 8.766709807679579), ((12.839934501779176, 11.300824688102473), (13.285114114146213, 14.10378570292717),(14.839934501779176, 16.300824688102473))]正如你所看到的,有一些具有多個(gè)坐標(biāo)的嵌套列表,所以我希望它看起來像這樣:temp =[(20.0, 15.076858380630263), (20.0, 16.92468707613784), (5.430012747754155, 3.3503228946034667), (7.364023506893538, 7.013767290971433), (11.932318028181742, 8.766709807679579), (12.839934501779176, 11.300824688102473), (13.285114114146213, 14.10378570292717), (14.839934501779176, 16.300824688102473)]這只是一個(gè)例子,我有一個(gè)巨大的輸出,不知道這些嵌套列表的位置,里面有多少個(gè)坐標(biāo)。但整體結(jié)構(gòu)是一樣的。謝謝。
1 回答

藍(lán)山帝景
TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊
您可以使用列表理解:
[j for i in temp for j in (i if isinstance(i[0], tuple) else [i])]
輸出:
[(20.0, 15.076858380630263),
(20.0, 16.92468707613784),
(5.430012747754155, 3.3503228946034667),
(7.364023506893538, 7.013767290971433),
(11.932318028181742, 8.766709807679579),
(12.839934501779176, 11.300824688102473),
(13.285114114146213, 14.10378570292717),
(14.839934501779176, 16.300824688102473)]
添加回答
舉報(bào)
0/150
提交
取消