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
  • 53
  • 1
  • 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
  • 14,755
  • 3
  • 14
  • 34
1

from the itertools doc page

from itertools import chain
def flatten(listOfLists):
    "Flatten one level of nesting"
    return chain.from_iterable(listOfLists)
rioV8
  • 24,506
  • 3
  • 32
  • 49