Is there an easy way to convert a list of doubles into a list of lists of doubles?
For example:
[1.0, 2.0, 3.0]
into
[[1.0], [2.0], [3.0]]
The code I'm using requires the second as inputs to a bunch of functions but it's annoying to have two copies of the same data.
Just use a list-comprehension wrapping each element in a list:
l = [1.0, 2.0, 3.0]
print [[x] for x in l]
[[1.0], [2.0], [3.0]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With