0

How to flatten the coordinates?

For input  :[(1,2),(5,6),(7,8)]

expecting the output as [1,2,5,6,7,8]

Sandeep M
  • 43
  • 7

2 Answers2

1

Try it like this:

mylist = [(1,2),(5,6),(7,8)]
newlist = []
for x in mylist:
  newlist += x
 
print(newlist)
Wasif
  • 13,656
  • 3
  • 11
  • 30
1

from the itertools doc page

from itertools import chain
def flatten(listOfLists):
    "Flatten one level of nesting"
    return chain.from_iterable(listOfLists)
rioV8
  • 18,123
  • 3
  • 18
  • 35