user1741339 user1741339 - 5 months ago 28
Python Question

flatten list in python

I want to flatten the list:

exampleArray = [[[151.68694121866872]],
[[101.59534468349297]],
[[72.16055999176308]]]


to:

[151.68694121866872, 101.59534468349297, 72.16055999176308]


Right now I am doing this:

resultArray= list(chain.from_iterable(list(chain.from_iterable(exampleArray))))


Even though it works I wanted to know if there's a better way.

Answer

How about

result = [x[0][0] for x in exampleArray]