user1741339 user1741339 - 1 year ago 113
Python Question

flatten list in python

I want to flatten the list:

exampleArray = [[[151.68694121866872]],


[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 Source

How about

result = [x[0][0] for x in exampleArray]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download