Is it possible to combine the following python list comprehensions into a single line? I know it's not necessary, I'm just curious.
rows = [row.split() for row in data]
flattened = [float(val) for sublist in rows for val in sublist]
Below is a snippet of the data file,
[' -.2098335E-03 -.2108988E-03 -.2119629E-03 -.2130240E-03 -.2140826E-03', ' -.2151421E-03 -.2161973E-03 -.2172531E-03 -.2183025E-03 -.2193489E-03', ' -.2203825E-03 -.2214097E-03 -.2224521E-03 -.2235475E-03 -.2246843E-03'....]
I'm trying to extract each of the strings and make a single list of numbers. The code above currently does that, I was wanting to see if it could get even more condensed.
Thanks!
datais?[float(val) for sublist in [row.split() for row in data] for val in sublist]