我有一个坐标列表如下: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))]正如你所看到的,有一些具有多个坐标的嵌套列表,所以我希望它看起来像这样: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)]这只是一个例子,我有一个巨大的输出,不知道这些嵌套列表的位置,里面有多少个坐标。但整体结构是一样的。谢谢。
1 回答
蓝山帝景
TA贡献1843条经验 获得超7个赞
您可以使用列表理解:
[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)]
添加回答
举报
0/150
提交
取消