-1

I have a list of coordinates as following:

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))]

As you can see there some nested lists with multiple coordinates, so I want it be look like the following:

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)]

This is just an example and I have a huge output and do not know where these nested listed located with how many coordinates inside it. But the overall structure is the same.

Thank you.

kederrac
  • 16,819
  • 6
  • 32
  • 55
ash
  • 55
  • 5
  • 1
    Please repeat the intro tour, especially [how to ask](https://stackoverflow.com/help/how-to-ask). There are many references on line for flattening lists; we expect you to post your coding attempt. – Prune Mar 24 '20 at 22:36

1 Answers1

1

you can use a list comprehension:

[j  for i in temp for j in (i if isinstance(i[0], tuple) else [i])]

output:

[(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)]
kederrac
  • 16,819
  • 6
  • 32
  • 55